{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "# 百度飞浆AI常规赛：MarTech Challenge 点击反欺诈预测"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "## 1.数据探索分析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "程序开始运行\n",
      "程序可以正常运行\n"
     ]
    }
   ],
   "source": [
    "#导包\r\n",
    "print(\"程序开始运行\")\r\n",
    "import pandas as pd\r\n",
    "import numpy as np\r\n",
    "\r\n",
    "pd.set_option('display.max_columns', None)\r\n",
    "print(\"程序可以正常运行\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "训练集的数据维度 (500000, 21) \t测试集的数据维度: (150000, 20)\n"
     ]
    }
   ],
   "source": [
    "#读取数据\r\n",
    "train=pd.read_csv('/home/aistudio/data/data97586/train.csv')\r\n",
    "test=pd.read_csv('/home/aistudio/data/data97586/test1.csv')\r\n",
    "print(\"训练集的数据维度\",train.shape,\"\\t测试集的数据维度:\",test.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Unnamed: 0', 'android_id', 'apptype', 'carrier', 'dev_height',\n",
       "       'dev_ppi', 'dev_width', 'label', 'lan', 'media_id', 'ntt', 'os', 'osv',\n",
       "       'package', 'sid', 'timestamp', 'version', 'fea_hash', 'location',\n",
       "       'fea1_hash', 'cus_type'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    257760\n",
       "1    242240\n",
       "Name: label, dtype: int64"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train['label'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.0    318597\n",
       "6.0    116548\n",
       "5.0     35021\n",
       "0.0     20617\n",
       "3.0      4463\n",
       "4.0      4446\n",
       "7.0       306\n",
       "1.0         2\n",
       "Name: ntt, dtype: int64"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train['ntt'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>android_id</th>\n",
       "      <th>apptype</th>\n",
       "      <th>carrier</th>\n",
       "      <th>dev_height</th>\n",
       "      <th>dev_ppi</th>\n",
       "      <th>dev_width</th>\n",
       "      <th>label</th>\n",
       "      <th>lan</th>\n",
       "      <th>media_id</th>\n",
       "      <th>ntt</th>\n",
       "      <th>os</th>\n",
       "      <th>osv</th>\n",
       "      <th>package</th>\n",
       "      <th>sid</th>\n",
       "      <th>timestamp</th>\n",
       "      <th>version</th>\n",
       "      <th>fea_hash</th>\n",
       "      <th>location</th>\n",
       "      <th>fea1_hash</th>\n",
       "      <th>cus_type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>316361</td>\n",
       "      <td>1199</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>104</td>\n",
       "      <td>6.0</td>\n",
       "      <td>android</td>\n",
       "      <td>9</td>\n",
       "      <td>18</td>\n",
       "      <td>1438873</td>\n",
       "      <td>1.559893e+12</td>\n",
       "      <td>8</td>\n",
       "      <td>2135019403</td>\n",
       "      <td>0</td>\n",
       "      <td>2329670524</td>\n",
       "      <td>601</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>135939</td>\n",
       "      <td>893</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>19</td>\n",
       "      <td>6.0</td>\n",
       "      <td>android</td>\n",
       "      <td>8.1</td>\n",
       "      <td>0</td>\n",
       "      <td>1185582</td>\n",
       "      <td>1.559994e+12</td>\n",
       "      <td>4</td>\n",
       "      <td>2782306428</td>\n",
       "      <td>1</td>\n",
       "      <td>2864801071</td>\n",
       "      <td>1000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>399254</td>\n",
       "      <td>821</td>\n",
       "      <td>0.0</td>\n",
       "      <td>760.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>360.0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>559</td>\n",
       "      <td>0.0</td>\n",
       "      <td>android</td>\n",
       "      <td>8.1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1555716</td>\n",
       "      <td>1.559837e+12</td>\n",
       "      <td>0</td>\n",
       "      <td>1392806005</td>\n",
       "      <td>2</td>\n",
       "      <td>628911675</td>\n",
       "      <td>696</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>68983</td>\n",
       "      <td>1004</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>2214.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1080.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>129</td>\n",
       "      <td>2.0</td>\n",
       "      <td>android</td>\n",
       "      <td>8.1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1093419</td>\n",
       "      <td>1.560042e+12</td>\n",
       "      <td>0</td>\n",
       "      <td>3562553457</td>\n",
       "      <td>3</td>\n",
       "      <td>1283809327</td>\n",
       "      <td>753</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>288999</td>\n",
       "      <td>1076</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>2280.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1080.0</td>\n",
       "      <td>1</td>\n",
       "      <td>zh-CN</td>\n",
       "      <td>64</td>\n",
       "      <td>2.0</td>\n",
       "      <td>android</td>\n",
       "      <td>8.0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1400089</td>\n",
       "      <td>1.559867e+12</td>\n",
       "      <td>5</td>\n",
       "      <td>2364522023</td>\n",
       "      <td>4</td>\n",
       "      <td>1510695983</td>\n",
       "      <td>582</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499995</th>\n",
       "      <td>499995</td>\n",
       "      <td>392477</td>\n",
       "      <td>1028</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>1920.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1080.0</td>\n",
       "      <td>1</td>\n",
       "      <td>zh-CN</td>\n",
       "      <td>144</td>\n",
       "      <td>6.0</td>\n",
       "      <td>Android</td>\n",
       "      <td>7.1.2</td>\n",
       "      <td>25</td>\n",
       "      <td>1546078</td>\n",
       "      <td>1.559834e+12</td>\n",
       "      <td>7</td>\n",
       "      <td>861755946</td>\n",
       "      <td>79</td>\n",
       "      <td>140647032</td>\n",
       "      <td>373</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499996</th>\n",
       "      <td>499996</td>\n",
       "      <td>346134</td>\n",
       "      <td>1001</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1424.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>720.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>29</td>\n",
       "      <td>2.0</td>\n",
       "      <td>android</td>\n",
       "      <td>8.1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1480612</td>\n",
       "      <td>1.559814e+12</td>\n",
       "      <td>3</td>\n",
       "      <td>1714444511</td>\n",
       "      <td>23</td>\n",
       "      <td>2745131047</td>\n",
       "      <td>525</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499997</th>\n",
       "      <td>499997</td>\n",
       "      <td>499635</td>\n",
       "      <td>761</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>1280.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>720.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>54</td>\n",
       "      <td>6.0</td>\n",
       "      <td>android</td>\n",
       "      <td>6.0.1</td>\n",
       "      <td>9</td>\n",
       "      <td>1698442</td>\n",
       "      <td>1.559676e+12</td>\n",
       "      <td>0</td>\n",
       "      <td>3843262581</td>\n",
       "      <td>25</td>\n",
       "      <td>1326115882</td>\n",
       "      <td>810</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499998</th>\n",
       "      <td>499998</td>\n",
       "      <td>239786</td>\n",
       "      <td>917</td>\n",
       "      <td>46001.0</td>\n",
       "      <td>960.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>540.0</td>\n",
       "      <td>0</td>\n",
       "      <td>zh_CN</td>\n",
       "      <td>109</td>\n",
       "      <td>2.0</td>\n",
       "      <td>android</td>\n",
       "      <td>5.1.1</td>\n",
       "      <td>0</td>\n",
       "      <td>1331155</td>\n",
       "      <td>1.559840e+12</td>\n",
       "      <td>0</td>\n",
       "      <td>1984296118</td>\n",
       "      <td>225</td>\n",
       "      <td>1446741112</td>\n",
       "      <td>772</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499999</th>\n",
       "      <td>499999</td>\n",
       "      <td>270531</td>\n",
       "      <td>929</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>2040.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1080.0</td>\n",
       "      <td>1</td>\n",
       "      <td>zh-CN</td>\n",
       "      <td>59</td>\n",
       "      <td>2.0</td>\n",
       "      <td>Android</td>\n",
       "      <td>8.1.0</td>\n",
       "      <td>78</td>\n",
       "      <td>1373973</td>\n",
       "      <td>1.559922e+12</td>\n",
       "      <td>5</td>\n",
       "      <td>1697301943</td>\n",
       "      <td>49</td>\n",
       "      <td>1915763579</td>\n",
       "      <td>1076</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>500000 rows × 21 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        Unnamed: 0  android_id  apptype  carrier  dev_height  dev_ppi  \\\n",
       "0                0      316361     1199  46000.0         0.0      0.0   \n",
       "1                1      135939      893      0.0         0.0      0.0   \n",
       "2                2      399254      821      0.0       760.0      0.0   \n",
       "3                3       68983     1004  46000.0      2214.0      0.0   \n",
       "4                4      288999     1076  46000.0      2280.0      0.0   \n",
       "...            ...         ...      ...      ...         ...      ...   \n",
       "499995      499995      392477     1028  46000.0      1920.0      3.0   \n",
       "499996      499996      346134     1001      0.0      1424.0      0.0   \n",
       "499997      499997      499635      761  46000.0      1280.0      0.0   \n",
       "499998      499998      239786      917  46001.0       960.0      0.0   \n",
       "499999      499999      270531      929  46000.0      2040.0      3.0   \n",
       "\n",
       "        dev_width  label    lan  media_id  ntt       os    osv  package  \\\n",
       "0             0.0      1    NaN       104  6.0  android      9       18   \n",
       "1             0.0      1    NaN        19  6.0  android    8.1        0   \n",
       "2           360.0      1    NaN       559  0.0  android  8.1.0        0   \n",
       "3          1080.0      0    NaN       129  2.0  android  8.1.0        0   \n",
       "4          1080.0      1  zh-CN        64  2.0  android  8.0.0        0   \n",
       "...           ...    ...    ...       ...  ...      ...    ...      ...   \n",
       "499995     1080.0      1  zh-CN       144  6.0  Android  7.1.2       25   \n",
       "499996      720.0      0    NaN        29  2.0  android  8.1.0        0   \n",
       "499997      720.0      0    NaN        54  6.0  android  6.0.1        9   \n",
       "499998      540.0      0  zh_CN       109  2.0  android  5.1.1        0   \n",
       "499999     1080.0      1  zh-CN        59  2.0  Android  8.1.0       78   \n",
       "\n",
       "            sid     timestamp version    fea_hash  location   fea1_hash  \\\n",
       "0       1438873  1.559893e+12       8  2135019403         0  2329670524   \n",
       "1       1185582  1.559994e+12       4  2782306428         1  2864801071   \n",
       "2       1555716  1.559837e+12       0  1392806005         2   628911675   \n",
       "3       1093419  1.560042e+12       0  3562553457         3  1283809327   \n",
       "4       1400089  1.559867e+12       5  2364522023         4  1510695983   \n",
       "...         ...           ...     ...         ...       ...         ...   \n",
       "499995  1546078  1.559834e+12       7   861755946        79   140647032   \n",
       "499996  1480612  1.559814e+12       3  1714444511        23  2745131047   \n",
       "499997  1698442  1.559676e+12       0  3843262581        25  1326115882   \n",
       "499998  1331155  1.559840e+12       0  1984296118       225  1446741112   \n",
       "499999  1373973  1.559922e+12       5  1697301943        49  1915763579   \n",
       "\n",
       "        cus_type  \n",
       "0            601  \n",
       "1           1000  \n",
       "2            696  \n",
       "3            753  \n",
       "4            582  \n",
       "...          ...  \n",
       "499995       373  \n",
       "499996       525  \n",
       "499997       810  \n",
       "499998       772  \n",
       "499999      1076  \n",
       "\n",
       "[500000 rows x 21 columns]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#先看一下train 和 test\r\n",
    "train#其实第一列Unnamed:0完全可以不要的  测试集也是"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Unnamed: 0</th>\n",
       "      <th>android_id</th>\n",
       "      <th>apptype</th>\n",
       "      <th>carrier</th>\n",
       "      <th>dev_height</th>\n",
       "      <th>dev_ppi</th>\n",
       "      <th>dev_width</th>\n",
       "      <th>lan</th>\n",
       "      <th>media_id</th>\n",
       "      <th>ntt</th>\n",
       "      <th>os</th>\n",
       "      <th>osv</th>\n",
       "      <th>package</th>\n",
       "      <th>sid</th>\n",
       "      <th>timestamp</th>\n",
       "      <th>version</th>\n",
       "      <th>fea_hash</th>\n",
       "      <th>location</th>\n",
       "      <th>fea1_hash</th>\n",
       "      <th>cus_type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>317625</td>\n",
       "      <td>1181</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>2196.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1080.0</td>\n",
       "      <td>CN</td>\n",
       "      <td>639</td>\n",
       "      <td>2.0</td>\n",
       "      <td>Android</td>\n",
       "      <td>8.1.0</td>\n",
       "      <td>188</td>\n",
       "      <td>1440682</td>\n",
       "      <td>1.559872e+12</td>\n",
       "      <td>7</td>\n",
       "      <td>1672223856</td>\n",
       "      <td>57</td>\n",
       "      <td>3872258917</td>\n",
       "      <td>658</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>435108</td>\n",
       "      <td>944</td>\n",
       "      <td>46003.0</td>\n",
       "      <td>2280.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1080.0</td>\n",
       "      <td>zh-CN</td>\n",
       "      <td>704</td>\n",
       "      <td>6.0</td>\n",
       "      <td>Android</td>\n",
       "      <td>8.1.0</td>\n",
       "      <td>221</td>\n",
       "      <td>1606824</td>\n",
       "      <td>1.559739e+12</td>\n",
       "      <td>3</td>\n",
       "      <td>3767901757</td>\n",
       "      <td>23</td>\n",
       "      <td>129322164</td>\n",
       "      <td>943</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>1106</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>39</td>\n",
       "      <td>2.0</td>\n",
       "      <td>android</td>\n",
       "      <td>5.1</td>\n",
       "      <td>1562</td>\n",
       "      <td>1774642</td>\n",
       "      <td>1.559614e+12</td>\n",
       "      <td>0</td>\n",
       "      <td>454638703</td>\n",
       "      <td>30</td>\n",
       "      <td>4226678391</td>\n",
       "      <td>411</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>451504</td>\n",
       "      <td>761</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>1344.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>720.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>54</td>\n",
       "      <td>2.0</td>\n",
       "      <td>android</td>\n",
       "      <td>7.1.1</td>\n",
       "      <td>9</td>\n",
       "      <td>1742535</td>\n",
       "      <td>1.559668e+12</td>\n",
       "      <td>0</td>\n",
       "      <td>1507622951</td>\n",
       "      <td>65</td>\n",
       "      <td>3355419572</td>\n",
       "      <td>848</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>1001</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>665.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>320.0</td>\n",
       "      <td>zh-CN</td>\n",
       "      <td>29</td>\n",
       "      <td>5.0</td>\n",
       "      <td>Android</td>\n",
       "      <td>8.1.0</td>\n",
       "      <td>4</td>\n",
       "      <td>1689686</td>\n",
       "      <td>1.559694e+12</td>\n",
       "      <td>0</td>\n",
       "      <td>4116351093</td>\n",
       "      <td>148</td>\n",
       "      <td>2644467751</td>\n",
       "      <td>411</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149995</th>\n",
       "      <td>149995</td>\n",
       "      <td>0</td>\n",
       "      <td>1001</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>760.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>360.0</td>\n",
       "      <td>zh-CN</td>\n",
       "      <td>29</td>\n",
       "      <td>2.0</td>\n",
       "      <td>Android</td>\n",
       "      <td>8.1.0</td>\n",
       "      <td>4</td>\n",
       "      <td>1165373</td>\n",
       "      <td>1.559957e+12</td>\n",
       "      <td>0</td>\n",
       "      <td>3162887451</td>\n",
       "      <td>126</td>\n",
       "      <td>2711576615</td>\n",
       "      <td>411</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149996</th>\n",
       "      <td>149996</td>\n",
       "      <td>0</td>\n",
       "      <td>1001</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>780.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>360.0</td>\n",
       "      <td>zh-CN</td>\n",
       "      <td>29</td>\n",
       "      <td>2.0</td>\n",
       "      <td>Android</td>\n",
       "      <td>9.0.0</td>\n",
       "      <td>4</td>\n",
       "      <td>1444115</td>\n",
       "      <td>1.559863e+12</td>\n",
       "      <td>0</td>\n",
       "      <td>97238959</td>\n",
       "      <td>322</td>\n",
       "      <td>2678022183</td>\n",
       "      <td>411</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149997</th>\n",
       "      <td>149997</td>\n",
       "      <td>0</td>\n",
       "      <td>1001</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>780.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>360.0</td>\n",
       "      <td>zh-CN</td>\n",
       "      <td>29</td>\n",
       "      <td>5.0</td>\n",
       "      <td>Android</td>\n",
       "      <td>8.1.0</td>\n",
       "      <td>4</td>\n",
       "      <td>1134378</td>\n",
       "      <td>1.560041e+12</td>\n",
       "      <td>0</td>\n",
       "      <td>1320118495</td>\n",
       "      <td>46</td>\n",
       "      <td>2610913319</td>\n",
       "      <td>411</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149998</th>\n",
       "      <td>149998</td>\n",
       "      <td>500925</td>\n",
       "      <td>1052</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>854.0</td>\n",
       "      <td>240.0</td>\n",
       "      <td>480.0</td>\n",
       "      <td>zh-CN</td>\n",
       "      <td>249</td>\n",
       "      <td>6.0</td>\n",
       "      <td>android</td>\n",
       "      <td>4.4.2</td>\n",
       "      <td>0</td>\n",
       "      <td>1700238</td>\n",
       "      <td>1.559688e+12</td>\n",
       "      <td>2</td>\n",
       "      <td>1292986591</td>\n",
       "      <td>41</td>\n",
       "      <td>1898209327</td>\n",
       "      <td>430</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149999</th>\n",
       "      <td>149999</td>\n",
       "      <td>0</td>\n",
       "      <td>1001</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>780.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>360.0</td>\n",
       "      <td>zh-CN</td>\n",
       "      <td>29</td>\n",
       "      <td>2.0</td>\n",
       "      <td>Android</td>\n",
       "      <td>9.0.0</td>\n",
       "      <td>4</td>\n",
       "      <td>1201539</td>\n",
       "      <td>1.559950e+12</td>\n",
       "      <td>0</td>\n",
       "      <td>259614175</td>\n",
       "      <td>122</td>\n",
       "      <td>2594136103</td>\n",
       "      <td>411</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>150000 rows × 20 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        Unnamed: 0  android_id  apptype  carrier  dev_height  dev_ppi  \\\n",
       "0                0      317625     1181  46000.0      2196.0      2.0   \n",
       "1                1      435108      944  46003.0      2280.0      3.0   \n",
       "2                2           0     1106  46000.0         0.0      0.0   \n",
       "3                3      451504      761  46000.0      1344.0      0.0   \n",
       "4                4           0     1001  46000.0       665.0      0.0   \n",
       "...            ...         ...      ...      ...         ...      ...   \n",
       "149995      149995           0     1001  46000.0       760.0      0.0   \n",
       "149996      149996           0     1001  46000.0       780.0      0.0   \n",
       "149997      149997           0     1001  46000.0       780.0      0.0   \n",
       "149998      149998      500925     1052  46000.0       854.0    240.0   \n",
       "149999      149999           0     1001  46000.0       780.0      0.0   \n",
       "\n",
       "        dev_width    lan  media_id  ntt       os    osv  package      sid  \\\n",
       "0          1080.0     CN       639  2.0  Android  8.1.0      188  1440682   \n",
       "1          1080.0  zh-CN       704  6.0  Android  8.1.0      221  1606824   \n",
       "2             0.0    NaN        39  2.0  android    5.1     1562  1774642   \n",
       "3           720.0    NaN        54  2.0  android  7.1.1        9  1742535   \n",
       "4           320.0  zh-CN        29  5.0  Android  8.1.0        4  1689686   \n",
       "...           ...    ...       ...  ...      ...    ...      ...      ...   \n",
       "149995      360.0  zh-CN        29  2.0  Android  8.1.0        4  1165373   \n",
       "149996      360.0  zh-CN        29  2.0  Android  9.0.0        4  1444115   \n",
       "149997      360.0  zh-CN        29  5.0  Android  8.1.0        4  1134378   \n",
       "149998      480.0  zh-CN       249  6.0  android  4.4.2        0  1700238   \n",
       "149999      360.0  zh-CN        29  2.0  Android  9.0.0        4  1201539   \n",
       "\n",
       "           timestamp version    fea_hash  location   fea1_hash  cus_type  \n",
       "0       1.559872e+12       7  1672223856        57  3872258917       658  \n",
       "1       1.559739e+12       3  3767901757        23   129322164       943  \n",
       "2       1.559614e+12       0   454638703        30  4226678391       411  \n",
       "3       1.559668e+12       0  1507622951        65  3355419572       848  \n",
       "4       1.559694e+12       0  4116351093       148  2644467751       411  \n",
       "...              ...     ...         ...       ...         ...       ...  \n",
       "149995  1.559957e+12       0  3162887451       126  2711576615       411  \n",
       "149996  1.559863e+12       0    97238959       322  2678022183       411  \n",
       "149997  1.560041e+12       0  1320118495        46  2610913319       411  \n",
       "149998  1.559688e+12       2  1292986591        41  1898209327       430  \n",
       "149999  1.559950e+12       0   259614175       122  2594136103       411  \n",
       "\n",
       "[150000 rows x 20 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>android_id</th>\n",
       "      <th>apptype</th>\n",
       "      <th>carrier</th>\n",
       "      <th>dev_height</th>\n",
       "      <th>dev_ppi</th>\n",
       "      <th>dev_width</th>\n",
       "      <th>label</th>\n",
       "      <th>lan</th>\n",
       "      <th>media_id</th>\n",
       "      <th>ntt</th>\n",
       "      <th>os</th>\n",
       "      <th>osv</th>\n",
       "      <th>package</th>\n",
       "      <th>sid</th>\n",
       "      <th>timestamp</th>\n",
       "      <th>version</th>\n",
       "      <th>fea_hash</th>\n",
       "      <th>location</th>\n",
       "      <th>fea1_hash</th>\n",
       "      <th>cus_type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>316361</td>\n",
       "      <td>1199</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>104</td>\n",
       "      <td>6.0</td>\n",
       "      <td>android</td>\n",
       "      <td>9</td>\n",
       "      <td>18</td>\n",
       "      <td>1438873</td>\n",
       "      <td>1.559893e+12</td>\n",
       "      <td>8</td>\n",
       "      <td>2135019403</td>\n",
       "      <td>0</td>\n",
       "      <td>2329670524</td>\n",
       "      <td>601</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>135939</td>\n",
       "      <td>893</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>19</td>\n",
       "      <td>6.0</td>\n",
       "      <td>android</td>\n",
       "      <td>8.1</td>\n",
       "      <td>0</td>\n",
       "      <td>1185582</td>\n",
       "      <td>1.559994e+12</td>\n",
       "      <td>4</td>\n",
       "      <td>2782306428</td>\n",
       "      <td>1</td>\n",
       "      <td>2864801071</td>\n",
       "      <td>1000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>399254</td>\n",
       "      <td>821</td>\n",
       "      <td>0.0</td>\n",
       "      <td>760.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>360.0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>559</td>\n",
       "      <td>0.0</td>\n",
       "      <td>android</td>\n",
       "      <td>8.1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1555716</td>\n",
       "      <td>1.559837e+12</td>\n",
       "      <td>0</td>\n",
       "      <td>1392806005</td>\n",
       "      <td>2</td>\n",
       "      <td>628911675</td>\n",
       "      <td>696</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>68983</td>\n",
       "      <td>1004</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>2214.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1080.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>129</td>\n",
       "      <td>2.0</td>\n",
       "      <td>android</td>\n",
       "      <td>8.1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1093419</td>\n",
       "      <td>1.560042e+12</td>\n",
       "      <td>0</td>\n",
       "      <td>3562553457</td>\n",
       "      <td>3</td>\n",
       "      <td>1283809327</td>\n",
       "      <td>753</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>288999</td>\n",
       "      <td>1076</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>2280.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1080.0</td>\n",
       "      <td>1</td>\n",
       "      <td>zh-CN</td>\n",
       "      <td>64</td>\n",
       "      <td>2.0</td>\n",
       "      <td>android</td>\n",
       "      <td>8.0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1400089</td>\n",
       "      <td>1.559867e+12</td>\n",
       "      <td>5</td>\n",
       "      <td>2364522023</td>\n",
       "      <td>4</td>\n",
       "      <td>1510695983</td>\n",
       "      <td>582</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499995</th>\n",
       "      <td>392477</td>\n",
       "      <td>1028</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>1920.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1080.0</td>\n",
       "      <td>1</td>\n",
       "      <td>zh-CN</td>\n",
       "      <td>144</td>\n",
       "      <td>6.0</td>\n",
       "      <td>Android</td>\n",
       "      <td>7.1.2</td>\n",
       "      <td>25</td>\n",
       "      <td>1546078</td>\n",
       "      <td>1.559834e+12</td>\n",
       "      <td>7</td>\n",
       "      <td>861755946</td>\n",
       "      <td>79</td>\n",
       "      <td>140647032</td>\n",
       "      <td>373</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499996</th>\n",
       "      <td>346134</td>\n",
       "      <td>1001</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1424.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>720.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>29</td>\n",
       "      <td>2.0</td>\n",
       "      <td>android</td>\n",
       "      <td>8.1.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1480612</td>\n",
       "      <td>1.559814e+12</td>\n",
       "      <td>3</td>\n",
       "      <td>1714444511</td>\n",
       "      <td>23</td>\n",
       "      <td>2745131047</td>\n",
       "      <td>525</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499997</th>\n",
       "      <td>499635</td>\n",
       "      <td>761</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>1280.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>720.0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>54</td>\n",
       "      <td>6.0</td>\n",
       "      <td>android</td>\n",
       "      <td>6.0.1</td>\n",
       "      <td>9</td>\n",
       "      <td>1698442</td>\n",
       "      <td>1.559676e+12</td>\n",
       "      <td>0</td>\n",
       "      <td>3843262581</td>\n",
       "      <td>25</td>\n",
       "      <td>1326115882</td>\n",
       "      <td>810</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499998</th>\n",
       "      <td>239786</td>\n",
       "      <td>917</td>\n",
       "      <td>46001.0</td>\n",
       "      <td>960.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>540.0</td>\n",
       "      <td>0</td>\n",
       "      <td>zh_CN</td>\n",
       "      <td>109</td>\n",
       "      <td>2.0</td>\n",
       "      <td>android</td>\n",
       "      <td>5.1.1</td>\n",
       "      <td>0</td>\n",
       "      <td>1331155</td>\n",
       "      <td>1.559840e+12</td>\n",
       "      <td>0</td>\n",
       "      <td>1984296118</td>\n",
       "      <td>225</td>\n",
       "      <td>1446741112</td>\n",
       "      <td>772</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499999</th>\n",
       "      <td>270531</td>\n",
       "      <td>929</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>2040.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1080.0</td>\n",
       "      <td>1</td>\n",
       "      <td>zh-CN</td>\n",
       "      <td>59</td>\n",
       "      <td>2.0</td>\n",
       "      <td>Android</td>\n",
       "      <td>8.1.0</td>\n",
       "      <td>78</td>\n",
       "      <td>1373973</td>\n",
       "      <td>1.559922e+12</td>\n",
       "      <td>5</td>\n",
       "      <td>1697301943</td>\n",
       "      <td>49</td>\n",
       "      <td>1915763579</td>\n",
       "      <td>1076</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>500000 rows × 20 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        android_id  apptype  carrier  dev_height  dev_ppi  dev_width  label  \\\n",
       "0           316361     1199  46000.0         0.0      0.0        0.0      1   \n",
       "1           135939      893      0.0         0.0      0.0        0.0      1   \n",
       "2           399254      821      0.0       760.0      0.0      360.0      1   \n",
       "3            68983     1004  46000.0      2214.0      0.0     1080.0      0   \n",
       "4           288999     1076  46000.0      2280.0      0.0     1080.0      1   \n",
       "...            ...      ...      ...         ...      ...        ...    ...   \n",
       "499995      392477     1028  46000.0      1920.0      3.0     1080.0      1   \n",
       "499996      346134     1001      0.0      1424.0      0.0      720.0      0   \n",
       "499997      499635      761  46000.0      1280.0      0.0      720.0      0   \n",
       "499998      239786      917  46001.0       960.0      0.0      540.0      0   \n",
       "499999      270531      929  46000.0      2040.0      3.0     1080.0      1   \n",
       "\n",
       "          lan  media_id  ntt       os    osv  package      sid     timestamp  \\\n",
       "0         NaN       104  6.0  android      9       18  1438873  1.559893e+12   \n",
       "1         NaN        19  6.0  android    8.1        0  1185582  1.559994e+12   \n",
       "2         NaN       559  0.0  android  8.1.0        0  1555716  1.559837e+12   \n",
       "3         NaN       129  2.0  android  8.1.0        0  1093419  1.560042e+12   \n",
       "4       zh-CN        64  2.0  android  8.0.0        0  1400089  1.559867e+12   \n",
       "...       ...       ...  ...      ...    ...      ...      ...           ...   \n",
       "499995  zh-CN       144  6.0  Android  7.1.2       25  1546078  1.559834e+12   \n",
       "499996    NaN        29  2.0  android  8.1.0        0  1480612  1.559814e+12   \n",
       "499997    NaN        54  6.0  android  6.0.1        9  1698442  1.559676e+12   \n",
       "499998  zh_CN       109  2.0  android  5.1.1        0  1331155  1.559840e+12   \n",
       "499999  zh-CN        59  2.0  Android  8.1.0       78  1373973  1.559922e+12   \n",
       "\n",
       "       version    fea_hash  location   fea1_hash  cus_type  \n",
       "0            8  2135019403         0  2329670524       601  \n",
       "1            4  2782306428         1  2864801071      1000  \n",
       "2            0  1392806005         2   628911675       696  \n",
       "3            0  3562553457         3  1283809327       753  \n",
       "4            5  2364522023         4  1510695983       582  \n",
       "...        ...         ...       ...         ...       ...  \n",
       "499995       7   861755946        79   140647032       373  \n",
       "499996       3  1714444511        23  2745131047       525  \n",
       "499997       0  3843262581        25  1326115882       810  \n",
       "499998       0  1984296118       225  1446741112       772  \n",
       "499999       5  1697301943        49  1915763579      1076  \n",
       "\n",
       "[500000 rows x 20 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#可以通过iloc的方法 去掉第一列 \r\n",
    "train=train.iloc[:,1:]\r\n",
    "train"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>android_id</th>\n",
       "      <th>apptype</th>\n",
       "      <th>carrier</th>\n",
       "      <th>dev_height</th>\n",
       "      <th>dev_ppi</th>\n",
       "      <th>dev_width</th>\n",
       "      <th>lan</th>\n",
       "      <th>media_id</th>\n",
       "      <th>ntt</th>\n",
       "      <th>os</th>\n",
       "      <th>osv</th>\n",
       "      <th>package</th>\n",
       "      <th>sid</th>\n",
       "      <th>timestamp</th>\n",
       "      <th>version</th>\n",
       "      <th>fea_hash</th>\n",
       "      <th>location</th>\n",
       "      <th>fea1_hash</th>\n",
       "      <th>cus_type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>317625</td>\n",
       "      <td>1181</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>2196.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1080.0</td>\n",
       "      <td>CN</td>\n",
       "      <td>639</td>\n",
       "      <td>2.0</td>\n",
       "      <td>Android</td>\n",
       "      <td>8.1.0</td>\n",
       "      <td>188</td>\n",
       "      <td>1440682</td>\n",
       "      <td>1.559872e+12</td>\n",
       "      <td>7</td>\n",
       "      <td>1672223856</td>\n",
       "      <td>57</td>\n",
       "      <td>3872258917</td>\n",
       "      <td>658</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>435108</td>\n",
       "      <td>944</td>\n",
       "      <td>46003.0</td>\n",
       "      <td>2280.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1080.0</td>\n",
       "      <td>zh-CN</td>\n",
       "      <td>704</td>\n",
       "      <td>6.0</td>\n",
       "      <td>Android</td>\n",
       "      <td>8.1.0</td>\n",
       "      <td>221</td>\n",
       "      <td>1606824</td>\n",
       "      <td>1.559739e+12</td>\n",
       "      <td>3</td>\n",
       "      <td>3767901757</td>\n",
       "      <td>23</td>\n",
       "      <td>129322164</td>\n",
       "      <td>943</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "      <td>1106</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>39</td>\n",
       "      <td>2.0</td>\n",
       "      <td>android</td>\n",
       "      <td>5.1</td>\n",
       "      <td>1562</td>\n",
       "      <td>1774642</td>\n",
       "      <td>1.559614e+12</td>\n",
       "      <td>0</td>\n",
       "      <td>454638703</td>\n",
       "      <td>30</td>\n",
       "      <td>4226678391</td>\n",
       "      <td>411</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>451504</td>\n",
       "      <td>761</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>1344.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>720.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>54</td>\n",
       "      <td>2.0</td>\n",
       "      <td>android</td>\n",
       "      <td>7.1.1</td>\n",
       "      <td>9</td>\n",
       "      <td>1742535</td>\n",
       "      <td>1.559668e+12</td>\n",
       "      <td>0</td>\n",
       "      <td>1507622951</td>\n",
       "      <td>65</td>\n",
       "      <td>3355419572</td>\n",
       "      <td>848</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>1001</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>665.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>320.0</td>\n",
       "      <td>zh-CN</td>\n",
       "      <td>29</td>\n",
       "      <td>5.0</td>\n",
       "      <td>Android</td>\n",
       "      <td>8.1.0</td>\n",
       "      <td>4</td>\n",
       "      <td>1689686</td>\n",
       "      <td>1.559694e+12</td>\n",
       "      <td>0</td>\n",
       "      <td>4116351093</td>\n",
       "      <td>148</td>\n",
       "      <td>2644467751</td>\n",
       "      <td>411</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149995</th>\n",
       "      <td>0</td>\n",
       "      <td>1001</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>760.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>360.0</td>\n",
       "      <td>zh-CN</td>\n",
       "      <td>29</td>\n",
       "      <td>2.0</td>\n",
       "      <td>Android</td>\n",
       "      <td>8.1.0</td>\n",
       "      <td>4</td>\n",
       "      <td>1165373</td>\n",
       "      <td>1.559957e+12</td>\n",
       "      <td>0</td>\n",
       "      <td>3162887451</td>\n",
       "      <td>126</td>\n",
       "      <td>2711576615</td>\n",
       "      <td>411</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149996</th>\n",
       "      <td>0</td>\n",
       "      <td>1001</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>780.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>360.0</td>\n",
       "      <td>zh-CN</td>\n",
       "      <td>29</td>\n",
       "      <td>2.0</td>\n",
       "      <td>Android</td>\n",
       "      <td>9.0.0</td>\n",
       "      <td>4</td>\n",
       "      <td>1444115</td>\n",
       "      <td>1.559863e+12</td>\n",
       "      <td>0</td>\n",
       "      <td>97238959</td>\n",
       "      <td>322</td>\n",
       "      <td>2678022183</td>\n",
       "      <td>411</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149997</th>\n",
       "      <td>0</td>\n",
       "      <td>1001</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>780.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>360.0</td>\n",
       "      <td>zh-CN</td>\n",
       "      <td>29</td>\n",
       "      <td>5.0</td>\n",
       "      <td>Android</td>\n",
       "      <td>8.1.0</td>\n",
       "      <td>4</td>\n",
       "      <td>1134378</td>\n",
       "      <td>1.560041e+12</td>\n",
       "      <td>0</td>\n",
       "      <td>1320118495</td>\n",
       "      <td>46</td>\n",
       "      <td>2610913319</td>\n",
       "      <td>411</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149998</th>\n",
       "      <td>500925</td>\n",
       "      <td>1052</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>854.0</td>\n",
       "      <td>240.0</td>\n",
       "      <td>480.0</td>\n",
       "      <td>zh-CN</td>\n",
       "      <td>249</td>\n",
       "      <td>6.0</td>\n",
       "      <td>android</td>\n",
       "      <td>4.4.2</td>\n",
       "      <td>0</td>\n",
       "      <td>1700238</td>\n",
       "      <td>1.559688e+12</td>\n",
       "      <td>2</td>\n",
       "      <td>1292986591</td>\n",
       "      <td>41</td>\n",
       "      <td>1898209327</td>\n",
       "      <td>430</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149999</th>\n",
       "      <td>0</td>\n",
       "      <td>1001</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>780.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>360.0</td>\n",
       "      <td>zh-CN</td>\n",
       "      <td>29</td>\n",
       "      <td>2.0</td>\n",
       "      <td>Android</td>\n",
       "      <td>9.0.0</td>\n",
       "      <td>4</td>\n",
       "      <td>1201539</td>\n",
       "      <td>1.559950e+12</td>\n",
       "      <td>0</td>\n",
       "      <td>259614175</td>\n",
       "      <td>122</td>\n",
       "      <td>2594136103</td>\n",
       "      <td>411</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>150000 rows × 19 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        android_id  apptype  carrier  dev_height  dev_ppi  dev_width    lan  \\\n",
       "0           317625     1181  46000.0      2196.0      2.0     1080.0     CN   \n",
       "1           435108      944  46003.0      2280.0      3.0     1080.0  zh-CN   \n",
       "2                0     1106  46000.0         0.0      0.0        0.0    NaN   \n",
       "3           451504      761  46000.0      1344.0      0.0      720.0    NaN   \n",
       "4                0     1001  46000.0       665.0      0.0      320.0  zh-CN   \n",
       "...            ...      ...      ...         ...      ...        ...    ...   \n",
       "149995           0     1001  46000.0       760.0      0.0      360.0  zh-CN   \n",
       "149996           0     1001  46000.0       780.0      0.0      360.0  zh-CN   \n",
       "149997           0     1001  46000.0       780.0      0.0      360.0  zh-CN   \n",
       "149998      500925     1052  46000.0       854.0    240.0      480.0  zh-CN   \n",
       "149999           0     1001  46000.0       780.0      0.0      360.0  zh-CN   \n",
       "\n",
       "        media_id  ntt       os    osv  package      sid     timestamp version  \\\n",
       "0            639  2.0  Android  8.1.0      188  1440682  1.559872e+12       7   \n",
       "1            704  6.0  Android  8.1.0      221  1606824  1.559739e+12       3   \n",
       "2             39  2.0  android    5.1     1562  1774642  1.559614e+12       0   \n",
       "3             54  2.0  android  7.1.1        9  1742535  1.559668e+12       0   \n",
       "4             29  5.0  Android  8.1.0        4  1689686  1.559694e+12       0   \n",
       "...          ...  ...      ...    ...      ...      ...           ...     ...   \n",
       "149995        29  2.0  Android  8.1.0        4  1165373  1.559957e+12       0   \n",
       "149996        29  2.0  Android  9.0.0        4  1444115  1.559863e+12       0   \n",
       "149997        29  5.0  Android  8.1.0        4  1134378  1.560041e+12       0   \n",
       "149998       249  6.0  android  4.4.2        0  1700238  1.559688e+12       2   \n",
       "149999        29  2.0  Android  9.0.0        4  1201539  1.559950e+12       0   \n",
       "\n",
       "          fea_hash  location   fea1_hash  cus_type  \n",
       "0       1672223856        57  3872258917       658  \n",
       "1       3767901757        23   129322164       943  \n",
       "2        454638703        30  4226678391       411  \n",
       "3       1507622951        65  3355419572       848  \n",
       "4       4116351093       148  2644467751       411  \n",
       "...            ...       ...         ...       ...  \n",
       "149995  3162887451       126  2711576615       411  \n",
       "149996    97238959       322  2678022183       411  \n",
       "149997  1320118495        46  2610913319       411  \n",
       "149998  1292986591        41  1898209327       430  \n",
       "149999   259614175       122  2594136103       411  \n",
       "\n",
       "[150000 rows x 19 columns]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test=test.iloc[:,1:]\r\n",
    "test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 500000 entries, 0 to 499999\n",
      "Data columns (total 20 columns):\n",
      " #   Column      Non-Null Count   Dtype  \n",
      "---  ------      --------------   -----  \n",
      " 0   android_id  500000 non-null  int64  \n",
      " 1   apptype     500000 non-null  int64  \n",
      " 2   carrier     500000 non-null  float64\n",
      " 3   dev_height  500000 non-null  float64\n",
      " 4   dev_ppi     500000 non-null  float64\n",
      " 5   dev_width   500000 non-null  float64\n",
      " 6   label       500000 non-null  int64  \n",
      " 7   lan         316720 non-null  object \n",
      " 8   media_id    500000 non-null  int64  \n",
      " 9   ntt         500000 non-null  float64\n",
      " 10  os          500000 non-null  object \n",
      " 11  osv         493439 non-null  object \n",
      " 12  package     500000 non-null  int64  \n",
      " 13  sid         500000 non-null  int64  \n",
      " 14  timestamp   500000 non-null  float64\n",
      " 15  version     500000 non-null  object \n",
      " 16  fea_hash    500000 non-null  object \n",
      " 17  location    500000 non-null  int64  \n",
      " 18  fea1_hash   500000 non-null  int64  \n",
      " 19  cus_type    500000 non-null  int64  \n",
      "dtypes: float64(6), int64(9), object(5)\n",
      "memory usage: 76.3+ MB\n"
     ]
    }
   ],
   "source": [
    "#进行一下数据的探索\r\n",
    "train.info()#这里面大部分是数值类型 还有很多不是 这个时候需要进行一下数据的探索分析  \r\n",
    "#比如lan os  osv  version fea_hash 这几个都是object类型 含义分别是语言 操作系统     操作系统版本 媒体版本app版本 用户特征编码(具体物理含义略去)             "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['lan', 'os', 'osv', 'version', 'fea_hash'], dtype='object')"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#可以用一个函数直接筛选出object类型 因为这类数据不能直接建模 需要转换为数值类型\r\n",
    "object_cols=train.select_dtypes(include='object').columns#这样就把所有的object类型给拿出来了\r\n",
    "object_cols"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "zh-CN          244474\n",
       "zh              30574\n",
       "cn              20685\n",
       "zh_CN           11602\n",
       "Zh-CN            8122\n",
       "zh-cn             642\n",
       "ZH                185\n",
       "CN                168\n",
       "tw                119\n",
       "en                 89\n",
       "zh_CN_#Hans        26\n",
       "ko                 11\n",
       "zh-TW               7\n",
       "en-US               3\n",
       "zh-HK               3\n",
       "it                  2\n",
       "TW                  2\n",
       "en-GB               2\n",
       "ja                  2\n",
       "mi                  1\n",
       "zh-MO               1\n",
       "Name: lan, dtype: int64"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#比如先探索一下lan这个数据\r\n",
    "train['lan'].value_counts()#可以看到这个是语言的分布情况  大部分是中文的 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "android_id         0\n",
       "apptype            0\n",
       "carrier            0\n",
       "dev_height         0\n",
       "dev_ppi            0\n",
       "dev_width          0\n",
       "label              0\n",
       "lan           183280\n",
       "media_id           0\n",
       "ntt                0\n",
       "os                 0\n",
       "osv             6561\n",
       "package            0\n",
       "sid                0\n",
       "timestamp          0\n",
       "version            0\n",
       "fea_hash           0\n",
       "location           0\n",
       "fea1_hash          0\n",
       "cus_type           0\n",
       "dtype: int64"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#缺失值的个数\r\n",
    "train.isnull().sum()#这样就得到了缺失值的分布情况  可以看到lan 设别的语言确实的比较多  osv操作系统版本也确实的比较多"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "lan    183280\n",
       "osv      6561\n",
       "dtype: int64"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#可以把这有缺失的拿出来\r\n",
    "temp=train.isnull().sum()\r\n",
    "temp[temp>0]#所有有缺失值的都看到了"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "### object类型 'lan', 'os', 'osv', 'version', 'fea_hash'   这几个特征'lan', 'os', 'osv', 'version'先不参与建模 \n",
    "### 有缺失值的列 lan osv         "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['android_id', 'apptype', 'carrier', 'dev_height', 'dev_ppi', 'dev_width', 'lan', 'media_id', 'ntt', 'os', 'osv', 'package', 'sid', 'timestamp', 'version', 'fea_hash', 'location', 'fea1_hash', 'cus_type'] 19\n"
     ]
    }
   ],
   "source": [
    "#拿到所有的特征\r\n",
    "features=train.columns.to_list()\r\n",
    "features.remove('label')\r\n",
    "print(features,len(features))#这样就拿到了 所有的特征 一共是19个"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "android_id  中唯一值的个数是: 362258\n",
      "apptype  中唯一值的个数是: 89\n",
      "carrier  中唯一值的个数是: 5\n",
      "dev_height  中唯一值的个数是: 798\n",
      "dev_ppi  中唯一值的个数是: 92\n",
      "dev_width  中唯一值的个数是: 346\n",
      "lan  中唯一值的个数是: 21\n",
      "media_id  中唯一值的个数是: 284\n",
      "ntt  中唯一值的个数是: 8\n",
      "os  中唯一值的个数是: 2\n",
      "osv  中唯一值的个数是: 154\n",
      "package  中唯一值的个数是: 1950\n",
      "sid  中唯一值的个数是: 500000\n",
      "timestamp  中唯一值的个数是: 500000\n",
      "version  中唯一值的个数是: 22\n",
      "fea_hash  中唯一值的个数是: 402980\n",
      "location  中唯一值的个数是: 332\n",
      "fea1_hash  中唯一值的个数是: 4959\n",
      "cus_type  中唯一值的个数是: 58\n"
     ]
    }
   ],
   "source": [
    "#看一下每个特征里面 唯一值的个数\r\n",
    "for feature in features:\r\n",
    "    print(feature,\" 中唯一值的个数是:\",train[feature].nunique())#可以看到android_id是很多 数字越大表示这个特征不同的情况越多  像os这只有两个 可以看看是什么情况"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "android    303175\n",
       "Android    196825\n",
       "Name: os, dtype: int64"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train['os'].value_counts()#哦 原来都是安卓 只是换了个马甲   这就说明这一列意义不大 因为全都是安卓"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['android_id', 'apptype', 'carrier', 'dev_height', 'dev_ppi', 'dev_width', 'lan', 'media_id', 'ntt', 'os', 'osv', 'package', 'sid', 'timestamp', 'version', 'fea_hash', 'location', 'fea1_hash', 'cus_type'] 19\n"
     ]
    }
   ],
   "source": [
    "print(features,len(features))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8.1.0            151419\n",
       "9                 71332\n",
       "6.0.1             31714\n",
       "7.1.1             26503\n",
       "9.0.0             24385\n",
       "                  ...  \n",
       "2.3.7                 1\n",
       "Android 4.3.1         1\n",
       "Android_4.2.1         1\n",
       "2.2.2                 1\n",
       "4.0                   1\n",
       "Name: osv, Length: 154, dtype: int64"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train['osv'].value_counts()#在第一个版本中 这个特征我们是去掉了的  本次要利用一下\r\n",
    "#这个操作系统的版本 是8的最多 其他的也有一些  不过具体到很详细了 这个时候需要再把特征转换一下  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8.1.0\t9\t6.0.1\t7.1.1\t9.0.0\t6.0\t5.1\t8.1\t5.1.1\t8.0.0\t7.1.2\t4.4.4\t7.0\tAndroid_8.1.0\tAndroid_9\t5.0.2\t7.9.0\t7.9.2\t8.0\t7.1\t9.0\t3.8.6\t4.4.2\t6.0.0\t5.1.0\t4.1\t2.3\t5.0\t4.3\t7.0.0\tAndroid_8.0.0\t4.4\tAndroid_7.1.1\t3.9.0\tAndroid_6.0.1\t7.8.9\t4.2.2\t7.8.7\t8.0.1\t5.0.1\tAndroid_5.1.1\tAndroid_7.1.2\t6.1\t7.8.0\t3.8.4\tAndroid_5.1\t8\t4.1.2\tAndroid_6.0\t5.0.0\t7.7.7\tAndroid_7.0\t7.8.2\t3.8.0\t21100\t7.7.3\tAndroid_4.4.4\t4.3.0\t7.2.1\t7\t4.2.1\t7.7.5\t6.1.0\t5.2\t7.8.4\t7.8.5\t7.7.2\t21000\t5\t4.1.1\t7.6.7\t7.7.0\t3.8.3\t6.0_23\t7.6.8\t3.7.6\t7.6.4\t7.8.8\tAndroid_5.0.2\t9.0.5\t3.7.8\t7.7.4\t7.1.3\t7.1.0\t7.6.9\t4.0.3\t4.0.4\t4.2\tAndroid_5.0\t4.4.5\t7.8.6\t6.2.1\t3.1.1\tAndroid_4.4.2\t4.4.3\tAndroid_4.3\t4.4.0\t6.0.1_19\t3.0.3\t2.3.6\t7930\t2.3.4\tAndroid_4.1.2\t6.1.2\t2.1.2\t6\t2.2.3\t4.3.3\t4.4W\t2.3.5\t7.3.1\t3.2\tAndroid_4.2.2\t4.4.2_19\t5.3.0-FL2-20180717.9010\t5.1_22\t5.3\t71200\t4.0.2\t7.6.6\t4.3.1\t5.2.0\t7910\t4.2.3.2\t5.3.0\t9.1\t5.1.1_22\t6.0.2\t4\t11\t3.2.0-FL2-20180726.9015\t10.3.3\t2.0.1\t5.1.1-F-20180719.9007\tAndroid_4.4.3\tf073b_changxiang_v01_b1b8_20180915\tAndroid_5.0.1\t5.0_21\t9.1.0\t6.0 十核2.0G_HD\t%E6%B1%9F%E7%81%B5OS+5.0\t5.0.3\tAndroid 5.12\tAndroid 4.2.9\tAndroid 7.1\t2.9.2\t8.0.2\t7920\t6.1.0-RS-20190305.1125\t2.3.7\tAndroid 4.3.1\tAndroid_4.2.1\t2.2.2\t4.0\t"
     ]
    }
   ],
   "source": [
    "for i in train['osv'].value_counts().index:\r\n",
    "    if type(i) == str:\r\n",
    "        print(i,end='\\t')#基本上全是str类型\r\n",
    "    else:\r\n",
    "        print(i,\"不是str类型\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0             9\n",
       "1           8.1\n",
       "2         8.1.0\n",
       "3         8.1.0\n",
       "4         8.0.0\n",
       "          ...  \n",
       "499995    7.1.2\n",
       "499996    8.1.0\n",
       "499997    6.0.1\n",
       "499998    5.1.1\n",
       "499999    8.1.0\n",
       "Name: osv, Length: 500000, dtype: object"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train['osv']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train['osv'].fillna(\"8.1.0\",inplace=True)\r\n",
    "train['osv'].isnull().sum()#这一下就没有缺失值了"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0         9.00\n",
       "1         8.10\n",
       "2         8.10\n",
       "3         8.10\n",
       "4         8.00\n",
       "          ... \n",
       "499995    7.12\n",
       "499996    8.10\n",
       "499997    6.01\n",
       "499998    5.11\n",
       "499999    8.10\n",
       "Name: osv, Length: 500000, dtype: float64"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def osv_trans(x):\r\n",
    "    x=str(x).replace('Android_','').replace('Android ','').replace('W','')\r\n",
    "    if str(x).find('.')>0:#如果字符串有 “.” \r\n",
    "        temp_index1=x.find('.')\r\n",
    "        if x.find(\" \")>0:\r\n",
    "            temp_index2=x.find(' ')\r\n",
    "        else:\r\n",
    "            temp_index2=len(x)\r\n",
    "\r\n",
    "        if x.find(\"-\")>0:\r\n",
    "            temp_index2=x.find('-')\r\n",
    "\r\n",
    "\r\n",
    "        result=x[0:temp_index1]+'.'+x[temp_index1+1:temp_index2].replace('.','')\r\n",
    "        try:\r\n",
    "            return float(result)\r\n",
    "        except:\r\n",
    "            return 0\r\n",
    "\r\n",
    "    try:\r\n",
    "        return float(x)\r\n",
    "    except:\r\n",
    "        return 0\r\n",
    "\r\n",
    "train['osv'].apply(osv_trans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8.100    185324\n",
       "9.000    104684\n",
       "6.010     32296\n",
       "7.110     27159\n",
       "6.000     25391\n",
       "          ...  \n",
       "4.232         1\n",
       "2.920         1\n",
       "8.020         1\n",
       "6.020         1\n",
       "5.120         1\n",
       "Name: osv, Length: 105, dtype: int64"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train['osv']=train['osv'].apply(osv_trans)\r\n",
    "train['osv'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "8.100     55297\n",
       "9.000     31491\n",
       "6.010      9653\n",
       "7.110      8297\n",
       "6.000      7605\n",
       "          ...  \n",
       "5.021         1\n",
       "4.460         1\n",
       "12.000        1\n",
       "2.230         1\n",
       "3.110         1\n",
       "Name: osv, Length: 90, dtype: int64"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test['osv'].fillna(\"8.1.0\",inplace=True)\r\n",
    "test['osv']=test['osv'].apply(osv_trans)\r\n",
    "print(test['osv'].isnull().sum())\r\n",
    "test['osv'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.559820e+12    1\n",
       "1.559740e+12    1\n",
       "1.559619e+12    1\n",
       "1.560056e+12    1\n",
       "1.559954e+12    1\n",
       "               ..\n",
       "1.559902e+12    1\n",
       "1.559993e+12    1\n",
       "1.559905e+12    1\n",
       "1.559927e+12    1\n",
       "1.559920e+12    1\n",
       "Name: timestamp, Length: 500000, dtype: int64"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train['timestamp'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0        1970-01-01 00:00:01.559892728\n",
       "1        1970-01-01 00:00:01.559994020\n",
       "2        1970-01-01 00:00:01.559836697\n",
       "3        1970-01-01 00:00:01.560041977\n",
       "4        1970-01-01 00:00:01.559867301\n",
       "                      ...             \n",
       "499995   1970-01-01 00:00:01.559834058\n",
       "499996   1970-01-01 00:00:01.559814054\n",
       "499997   1970-01-01 00:00:01.559675697\n",
       "499998   1970-01-01 00:00:01.559840367\n",
       "499999   1970-01-01 00:00:01.559921566\n",
       "Name: timestamp, Length: 500000, dtype: datetime64[ns]"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#将其转化成时间的格式\r\n",
    "pd.to_datetime(train['timestamp']/1000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0        2019-06-07 15:32:08.241721\n",
       "1        2019-06-08 19:40:20.922229\n",
       "2        2019-06-06 23:58:17.549109\n",
       "3        2019-06-09 08:59:37.719685\n",
       "4        2019-06-07 08:28:21.478553\n",
       "                    ...            \n",
       "499995   2019-06-06 23:14:18.267242\n",
       "499996   2019-06-06 17:40:54.045280\n",
       "499997   2019-06-05 03:14:57.290064\n",
       "499998   2019-06-07 00:59:27.651521\n",
       "499999   2019-06-07 23:32:46.472229\n",
       "Name: timestamp, Length: 500000, dtype: datetime64[ns]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from datetime import datetime\r\n",
    "\r\n",
    "train['timestamp'].apply(lambda x:datetime.fromtimestamp(x/1000))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0        2019-06-07 15:32:08.241721\n",
       "1        2019-06-08 19:40:20.922229\n",
       "2        2019-06-06 23:58:17.549109\n",
       "3        2019-06-09 08:59:37.719685\n",
       "4        2019-06-07 08:28:21.478553\n",
       "                    ...            \n",
       "499995   2019-06-06 23:14:18.267242\n",
       "499996   2019-06-06 17:40:54.045280\n",
       "499997   2019-06-05 03:14:57.290064\n",
       "499998   2019-06-07 00:59:27.651521\n",
       "499999   2019-06-07 23:32:46.472229\n",
       "Name: timestamp, Length: 500000, dtype: datetime64[ns]"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train['timestamp']=train['timestamp'].apply(lambda x:datetime.fromtimestamp(x/1000))\r\n",
    "train['timestamp']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0        2019-06-07 09:43:20.477148\n",
       "1        2019-06-05 20:53:33.449314\n",
       "2        2019-06-04 10:08:24.732394\n",
       "3        2019-06-05 01:03:10.643892\n",
       "4        2019-06-05 08:16:34.450110\n",
       "                    ...            \n",
       "149995   2019-06-08 09:21:33.629823\n",
       "149996   2019-06-07 07:15:57.431662\n",
       "149997   2019-06-09 08:48:59.661749\n",
       "149998   2019-06-05 06:38:14.527250\n",
       "149999   2019-06-08 07:23:16.149025\n",
       "Name: timestamp, Length: 150000, dtype: datetime64[ns]"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test['timestamp']=test['timestamp'].apply(lambda x:datetime.fromtimestamp(x/1000))\r\n",
    "test['timestamp']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1625922487.7295568"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import time\r\n",
    "time.time()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['android_id', 'apptype', 'carrier', 'dev_height', 'dev_ppi', 'dev_width', 'media_id', 'ntt', 'osv', 'package', 'sid', 'timestamp', 'version', 'fea_hash', 'location', 'fea1_hash', 'cus_type'] 17\n"
     ]
    }
   ],
   "source": [
    "#把 'lan', 'os', 'osv', 'version'这几个特征不要了\r\n",
    "remove_list=['lan', 'os']\r\n",
    "col=features\r\n",
    "for i in remove_list:\r\n",
    "    col.remove(i)\r\n",
    "print(col,len(col))#这样去掉了那几个不想要的特征"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['android_id', 'apptype', 'carrier', 'dev_height', 'dev_ppi', 'dev_width', 'media_id', 'ntt', 'osv', 'package', 'sid', 'timestamp', 'version', 'fea_hash', 'location', 'fea1_hash', 'cus_type'] 17\n"
     ]
    }
   ],
   "source": [
    "print(features,len(features))#col=feature之后  改动col还是把feartures改了"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "17 17\n"
     ]
    }
   ],
   "source": [
    "print(len(col),len(features))#"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>android_id</th>\n",
       "      <th>apptype</th>\n",
       "      <th>carrier</th>\n",
       "      <th>dev_height</th>\n",
       "      <th>dev_ppi</th>\n",
       "      <th>dev_width</th>\n",
       "      <th>media_id</th>\n",
       "      <th>ntt</th>\n",
       "      <th>osv</th>\n",
       "      <th>package</th>\n",
       "      <th>sid</th>\n",
       "      <th>timestamp</th>\n",
       "      <th>version</th>\n",
       "      <th>fea_hash</th>\n",
       "      <th>location</th>\n",
       "      <th>fea1_hash</th>\n",
       "      <th>cus_type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>316361</td>\n",
       "      <td>1199</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>104</td>\n",
       "      <td>6.0</td>\n",
       "      <td>9.00</td>\n",
       "      <td>18</td>\n",
       "      <td>1438873</td>\n",
       "      <td>2019-06-07 15:32:08.241721</td>\n",
       "      <td>8</td>\n",
       "      <td>2135019403</td>\n",
       "      <td>0</td>\n",
       "      <td>2329670524</td>\n",
       "      <td>601</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>135939</td>\n",
       "      <td>893</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>19</td>\n",
       "      <td>6.0</td>\n",
       "      <td>8.10</td>\n",
       "      <td>0</td>\n",
       "      <td>1185582</td>\n",
       "      <td>2019-06-08 19:40:20.922229</td>\n",
       "      <td>4</td>\n",
       "      <td>2782306428</td>\n",
       "      <td>1</td>\n",
       "      <td>2864801071</td>\n",
       "      <td>1000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>399254</td>\n",
       "      <td>821</td>\n",
       "      <td>0.0</td>\n",
       "      <td>760.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>360.0</td>\n",
       "      <td>559</td>\n",
       "      <td>0.0</td>\n",
       "      <td>8.10</td>\n",
       "      <td>0</td>\n",
       "      <td>1555716</td>\n",
       "      <td>2019-06-06 23:58:17.549109</td>\n",
       "      <td>0</td>\n",
       "      <td>1392806005</td>\n",
       "      <td>2</td>\n",
       "      <td>628911675</td>\n",
       "      <td>696</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>68983</td>\n",
       "      <td>1004</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>2214.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1080.0</td>\n",
       "      <td>129</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8.10</td>\n",
       "      <td>0</td>\n",
       "      <td>1093419</td>\n",
       "      <td>2019-06-09 08:59:37.719685</td>\n",
       "      <td>0</td>\n",
       "      <td>3562553457</td>\n",
       "      <td>3</td>\n",
       "      <td>1283809327</td>\n",
       "      <td>753</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>288999</td>\n",
       "      <td>1076</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>2280.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1080.0</td>\n",
       "      <td>64</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8.00</td>\n",
       "      <td>0</td>\n",
       "      <td>1400089</td>\n",
       "      <td>2019-06-07 08:28:21.478553</td>\n",
       "      <td>5</td>\n",
       "      <td>2364522023</td>\n",
       "      <td>4</td>\n",
       "      <td>1510695983</td>\n",
       "      <td>582</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499995</th>\n",
       "      <td>392477</td>\n",
       "      <td>1028</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>1920.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1080.0</td>\n",
       "      <td>144</td>\n",
       "      <td>6.0</td>\n",
       "      <td>7.12</td>\n",
       "      <td>25</td>\n",
       "      <td>1546078</td>\n",
       "      <td>2019-06-06 23:14:18.267242</td>\n",
       "      <td>7</td>\n",
       "      <td>861755946</td>\n",
       "      <td>79</td>\n",
       "      <td>140647032</td>\n",
       "      <td>373</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499996</th>\n",
       "      <td>346134</td>\n",
       "      <td>1001</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1424.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>720.0</td>\n",
       "      <td>29</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8.10</td>\n",
       "      <td>0</td>\n",
       "      <td>1480612</td>\n",
       "      <td>2019-06-06 17:40:54.045280</td>\n",
       "      <td>3</td>\n",
       "      <td>1714444511</td>\n",
       "      <td>23</td>\n",
       "      <td>2745131047</td>\n",
       "      <td>525</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499997</th>\n",
       "      <td>499635</td>\n",
       "      <td>761</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>1280.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>720.0</td>\n",
       "      <td>54</td>\n",
       "      <td>6.0</td>\n",
       "      <td>6.01</td>\n",
       "      <td>9</td>\n",
       "      <td>1698442</td>\n",
       "      <td>2019-06-05 03:14:57.290064</td>\n",
       "      <td>0</td>\n",
       "      <td>3843262581</td>\n",
       "      <td>25</td>\n",
       "      <td>1326115882</td>\n",
       "      <td>810</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499998</th>\n",
       "      <td>239786</td>\n",
       "      <td>917</td>\n",
       "      <td>46001.0</td>\n",
       "      <td>960.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>540.0</td>\n",
       "      <td>109</td>\n",
       "      <td>2.0</td>\n",
       "      <td>5.11</td>\n",
       "      <td>0</td>\n",
       "      <td>1331155</td>\n",
       "      <td>2019-06-07 00:59:27.651521</td>\n",
       "      <td>0</td>\n",
       "      <td>1984296118</td>\n",
       "      <td>225</td>\n",
       "      <td>1446741112</td>\n",
       "      <td>772</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499999</th>\n",
       "      <td>270531</td>\n",
       "      <td>929</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>2040.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1080.0</td>\n",
       "      <td>59</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8.10</td>\n",
       "      <td>78</td>\n",
       "      <td>1373973</td>\n",
       "      <td>2019-06-07 23:32:46.472229</td>\n",
       "      <td>5</td>\n",
       "      <td>1697301943</td>\n",
       "      <td>49</td>\n",
       "      <td>1915763579</td>\n",
       "      <td>1076</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>500000 rows × 17 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        android_id  apptype  carrier  dev_height  dev_ppi  dev_width  \\\n",
       "0           316361     1199  46000.0         0.0      0.0        0.0   \n",
       "1           135939      893      0.0         0.0      0.0        0.0   \n",
       "2           399254      821      0.0       760.0      0.0      360.0   \n",
       "3            68983     1004  46000.0      2214.0      0.0     1080.0   \n",
       "4           288999     1076  46000.0      2280.0      0.0     1080.0   \n",
       "...            ...      ...      ...         ...      ...        ...   \n",
       "499995      392477     1028  46000.0      1920.0      3.0     1080.0   \n",
       "499996      346134     1001      0.0      1424.0      0.0      720.0   \n",
       "499997      499635      761  46000.0      1280.0      0.0      720.0   \n",
       "499998      239786      917  46001.0       960.0      0.0      540.0   \n",
       "499999      270531      929  46000.0      2040.0      3.0     1080.0   \n",
       "\n",
       "        media_id  ntt   osv  package      sid                  timestamp  \\\n",
       "0            104  6.0  9.00       18  1438873 2019-06-07 15:32:08.241721   \n",
       "1             19  6.0  8.10        0  1185582 2019-06-08 19:40:20.922229   \n",
       "2            559  0.0  8.10        0  1555716 2019-06-06 23:58:17.549109   \n",
       "3            129  2.0  8.10        0  1093419 2019-06-09 08:59:37.719685   \n",
       "4             64  2.0  8.00        0  1400089 2019-06-07 08:28:21.478553   \n",
       "...          ...  ...   ...      ...      ...                        ...   \n",
       "499995       144  6.0  7.12       25  1546078 2019-06-06 23:14:18.267242   \n",
       "499996        29  2.0  8.10        0  1480612 2019-06-06 17:40:54.045280   \n",
       "499997        54  6.0  6.01        9  1698442 2019-06-05 03:14:57.290064   \n",
       "499998       109  2.0  5.11        0  1331155 2019-06-07 00:59:27.651521   \n",
       "499999        59  2.0  8.10       78  1373973 2019-06-07 23:32:46.472229   \n",
       "\n",
       "       version    fea_hash  location   fea1_hash  cus_type  \n",
       "0            8  2135019403         0  2329670524       601  \n",
       "1            4  2782306428         1  2864801071      1000  \n",
       "2            0  1392806005         2   628911675       696  \n",
       "3            0  3562553457         3  1283809327       753  \n",
       "4            5  2364522023         4  1510695983       582  \n",
       "...        ...         ...       ...         ...       ...  \n",
       "499995       7   861755946        79   140647032       373  \n",
       "499996       3  1714444511        23  2745131047       525  \n",
       "499997       0  3843262581        25  1326115882       810  \n",
       "499998       0  1984296118       225  1446741112       772  \n",
       "499999       5  1697301943        49  1915763579      1076  \n",
       "\n",
       "[500000 rows x 17 columns]"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#根据特征拿到训练数据\r\n",
    "features=train[col]\r\n",
    "features#现在就得到了15行的数据 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0         1\n",
       "1         1\n",
       "2         1\n",
       "3         0\n",
       "4         1\n",
       "         ..\n",
       "499995    1\n",
       "499996    0\n",
       "499997    0\n",
       "499998    0\n",
       "499999    1\n",
       "Name: label, Length: 500000, dtype: int64"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#再看一下标签\r\n",
    "train['label']#标签也是没有问题的\r\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0         2329670524\n",
       "1         2864801071\n",
       "2          628911675\n",
       "3         1283809327\n",
       "4         1510695983\n",
       "             ...    \n",
       "499995     140647032\n",
       "499996    2745131047\n",
       "499997    1326115882\n",
       "499998    1446741112\n",
       "499999    1915763579\n",
       "Name: fea1_hash, Length: 500000, dtype: int64"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "features['fea1_hash']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10    391669\n",
       "9      99347\n",
       "8       8977\n",
       "7          6\n",
       "5          1\n",
       "Name: fea1_hash, dtype: int64"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#把这个features\r\n",
    "features['fea1_hash'].map(lambda x:len(str(x)) ).value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/ipykernel_launcher.py:2: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  \n",
      "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/ipykernel_launcher.py:3: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  This is separate from the ipykernel package so we can avoid doing imports until\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>android_id</th>\n",
       "      <th>apptype</th>\n",
       "      <th>carrier</th>\n",
       "      <th>dev_height</th>\n",
       "      <th>dev_ppi</th>\n",
       "      <th>dev_width</th>\n",
       "      <th>media_id</th>\n",
       "      <th>ntt</th>\n",
       "      <th>osv</th>\n",
       "      <th>package</th>\n",
       "      <th>sid</th>\n",
       "      <th>timestamp</th>\n",
       "      <th>version</th>\n",
       "      <th>fea_hash</th>\n",
       "      <th>location</th>\n",
       "      <th>fea1_hash</th>\n",
       "      <th>cus_type</th>\n",
       "      <th>fea_hash_len</th>\n",
       "      <th>fea1_hash_len</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>316361</td>\n",
       "      <td>1199</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>104</td>\n",
       "      <td>6.0</td>\n",
       "      <td>9.00</td>\n",
       "      <td>18</td>\n",
       "      <td>1438873</td>\n",
       "      <td>2019-06-07 15:32:08.241721</td>\n",
       "      <td>8</td>\n",
       "      <td>2135019403</td>\n",
       "      <td>0</td>\n",
       "      <td>2329670524</td>\n",
       "      <td>601</td>\n",
       "      <td>10</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>135939</td>\n",
       "      <td>893</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>19</td>\n",
       "      <td>6.0</td>\n",
       "      <td>8.10</td>\n",
       "      <td>0</td>\n",
       "      <td>1185582</td>\n",
       "      <td>2019-06-08 19:40:20.922229</td>\n",
       "      <td>4</td>\n",
       "      <td>2782306428</td>\n",
       "      <td>1</td>\n",
       "      <td>2864801071</td>\n",
       "      <td>1000</td>\n",
       "      <td>10</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>399254</td>\n",
       "      <td>821</td>\n",
       "      <td>0.0</td>\n",
       "      <td>760.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>360.0</td>\n",
       "      <td>559</td>\n",
       "      <td>0.0</td>\n",
       "      <td>8.10</td>\n",
       "      <td>0</td>\n",
       "      <td>1555716</td>\n",
       "      <td>2019-06-06 23:58:17.549109</td>\n",
       "      <td>0</td>\n",
       "      <td>1392806005</td>\n",
       "      <td>2</td>\n",
       "      <td>628911675</td>\n",
       "      <td>696</td>\n",
       "      <td>10</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>68983</td>\n",
       "      <td>1004</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>2214.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1080.0</td>\n",
       "      <td>129</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8.10</td>\n",
       "      <td>0</td>\n",
       "      <td>1093419</td>\n",
       "      <td>2019-06-09 08:59:37.719685</td>\n",
       "      <td>0</td>\n",
       "      <td>3562553457</td>\n",
       "      <td>3</td>\n",
       "      <td>1283809327</td>\n",
       "      <td>753</td>\n",
       "      <td>10</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>288999</td>\n",
       "      <td>1076</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>2280.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1080.0</td>\n",
       "      <td>64</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8.00</td>\n",
       "      <td>0</td>\n",
       "      <td>1400089</td>\n",
       "      <td>2019-06-07 08:28:21.478553</td>\n",
       "      <td>5</td>\n",
       "      <td>2364522023</td>\n",
       "      <td>4</td>\n",
       "      <td>1510695983</td>\n",
       "      <td>582</td>\n",
       "      <td>10</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499995</th>\n",
       "      <td>392477</td>\n",
       "      <td>1028</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>1920.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1080.0</td>\n",
       "      <td>144</td>\n",
       "      <td>6.0</td>\n",
       "      <td>7.12</td>\n",
       "      <td>25</td>\n",
       "      <td>1546078</td>\n",
       "      <td>2019-06-06 23:14:18.267242</td>\n",
       "      <td>7</td>\n",
       "      <td>861755946</td>\n",
       "      <td>79</td>\n",
       "      <td>140647032</td>\n",
       "      <td>373</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499996</th>\n",
       "      <td>346134</td>\n",
       "      <td>1001</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1424.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>720.0</td>\n",
       "      <td>29</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8.10</td>\n",
       "      <td>0</td>\n",
       "      <td>1480612</td>\n",
       "      <td>2019-06-06 17:40:54.045280</td>\n",
       "      <td>3</td>\n",
       "      <td>1714444511</td>\n",
       "      <td>23</td>\n",
       "      <td>2745131047</td>\n",
       "      <td>525</td>\n",
       "      <td>10</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499997</th>\n",
       "      <td>499635</td>\n",
       "      <td>761</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>1280.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>720.0</td>\n",
       "      <td>54</td>\n",
       "      <td>6.0</td>\n",
       "      <td>6.01</td>\n",
       "      <td>9</td>\n",
       "      <td>1698442</td>\n",
       "      <td>2019-06-05 03:14:57.290064</td>\n",
       "      <td>0</td>\n",
       "      <td>3843262581</td>\n",
       "      <td>25</td>\n",
       "      <td>1326115882</td>\n",
       "      <td>810</td>\n",
       "      <td>10</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499998</th>\n",
       "      <td>239786</td>\n",
       "      <td>917</td>\n",
       "      <td>46001.0</td>\n",
       "      <td>960.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>540.0</td>\n",
       "      <td>109</td>\n",
       "      <td>2.0</td>\n",
       "      <td>5.11</td>\n",
       "      <td>0</td>\n",
       "      <td>1331155</td>\n",
       "      <td>2019-06-07 00:59:27.651521</td>\n",
       "      <td>0</td>\n",
       "      <td>1984296118</td>\n",
       "      <td>225</td>\n",
       "      <td>1446741112</td>\n",
       "      <td>772</td>\n",
       "      <td>10</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499999</th>\n",
       "      <td>270531</td>\n",
       "      <td>929</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>2040.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1080.0</td>\n",
       "      <td>59</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8.10</td>\n",
       "      <td>78</td>\n",
       "      <td>1373973</td>\n",
       "      <td>2019-06-07 23:32:46.472229</td>\n",
       "      <td>5</td>\n",
       "      <td>1697301943</td>\n",
       "      <td>49</td>\n",
       "      <td>1915763579</td>\n",
       "      <td>1076</td>\n",
       "      <td>10</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>500000 rows × 19 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        android_id  apptype  carrier  dev_height  dev_ppi  dev_width  \\\n",
       "0           316361     1199  46000.0         0.0      0.0        0.0   \n",
       "1           135939      893      0.0         0.0      0.0        0.0   \n",
       "2           399254      821      0.0       760.0      0.0      360.0   \n",
       "3            68983     1004  46000.0      2214.0      0.0     1080.0   \n",
       "4           288999     1076  46000.0      2280.0      0.0     1080.0   \n",
       "...            ...      ...      ...         ...      ...        ...   \n",
       "499995      392477     1028  46000.0      1920.0      3.0     1080.0   \n",
       "499996      346134     1001      0.0      1424.0      0.0      720.0   \n",
       "499997      499635      761  46000.0      1280.0      0.0      720.0   \n",
       "499998      239786      917  46001.0       960.0      0.0      540.0   \n",
       "499999      270531      929  46000.0      2040.0      3.0     1080.0   \n",
       "\n",
       "        media_id  ntt   osv  package      sid                  timestamp  \\\n",
       "0            104  6.0  9.00       18  1438873 2019-06-07 15:32:08.241721   \n",
       "1             19  6.0  8.10        0  1185582 2019-06-08 19:40:20.922229   \n",
       "2            559  0.0  8.10        0  1555716 2019-06-06 23:58:17.549109   \n",
       "3            129  2.0  8.10        0  1093419 2019-06-09 08:59:37.719685   \n",
       "4             64  2.0  8.00        0  1400089 2019-06-07 08:28:21.478553   \n",
       "...          ...  ...   ...      ...      ...                        ...   \n",
       "499995       144  6.0  7.12       25  1546078 2019-06-06 23:14:18.267242   \n",
       "499996        29  2.0  8.10        0  1480612 2019-06-06 17:40:54.045280   \n",
       "499997        54  6.0  6.01        9  1698442 2019-06-05 03:14:57.290064   \n",
       "499998       109  2.0  5.11        0  1331155 2019-06-07 00:59:27.651521   \n",
       "499999        59  2.0  8.10       78  1373973 2019-06-07 23:32:46.472229   \n",
       "\n",
       "       version    fea_hash  location   fea1_hash  cus_type  fea_hash_len  \\\n",
       "0            8  2135019403         0  2329670524       601            10   \n",
       "1            4  2782306428         1  2864801071      1000            10   \n",
       "2            0  1392806005         2   628911675       696            10   \n",
       "3            0  3562553457         3  1283809327       753            10   \n",
       "4            5  2364522023         4  1510695983       582            10   \n",
       "...        ...         ...       ...         ...       ...           ...   \n",
       "499995       7   861755946        79   140647032       373             9   \n",
       "499996       3  1714444511        23  2745131047       525            10   \n",
       "499997       0  3843262581        25  1326115882       810            10   \n",
       "499998       0  1984296118       225  1446741112       772            10   \n",
       "499999       5  1697301943        49  1915763579      1076            10   \n",
       "\n",
       "        fea1_hash_len  \n",
       "0                  10  \n",
       "1                  10  \n",
       "2                   9  \n",
       "3                  10  \n",
       "4                  10  \n",
       "...               ...  \n",
       "499995              9  \n",
       "499996             10  \n",
       "499997             10  \n",
       "499998             10  \n",
       "499999             10  \n",
       "\n",
       "[500000 rows x 19 columns]"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#先把那个 fea_hash 和 fea1_hash 做一下转换 那个数字太大了  先按照长度来分一下\r\n",
    "features['fea_hash_len']=features['fea_hash'].map(lambda x:len(str(x)) )\r\n",
    "features['fea1_hash_len']=features['fea1_hash'].map(lambda x:len(str(x)) )\r\n",
    "features"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/ipykernel_launcher.py:2: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  \n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "68083895      110\n",
       "235856055      99\n",
       "0              92\n",
       "51306679       91\n",
       "2815114810     77\n",
       "             ... \n",
       "2148653681      1\n",
       "1087175738      1\n",
       "1906064186      1\n",
       "2215573879      1\n",
       "3860919416      1\n",
       "Name: fea_hash, Length: 402890, dtype: int64"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#如果fea_hash很长 那么就认为是异常的 就置为0  否则就是它自己\r\n",
    "features['fea_hash']=features['fea_hash'].map(lambda x:0 if len(x)>16 else int(x))\r\n",
    "features['fea_hash'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/ipykernel_launcher.py:1: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  \"\"\"Entry point for launching an IPython kernel.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "0         2329670524\n",
       "1         2864801071\n",
       "2          628911675\n",
       "3         1283809327\n",
       "4         1510695983\n",
       "             ...    \n",
       "499995     140647032\n",
       "499996    2745131047\n",
       "499997    1326115882\n",
       "499998    1446741112\n",
       "499999    1915763579\n",
       "Name: fea1_hash, Length: 500000, dtype: int64"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "features['fea1_hash']=features['fea1_hash'].map(lambda x:0 if len(str(x))>16 else int(x))\r\n",
    "features['fea1_hash']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4190764663    28393\n",
       "2329670524    24969\n",
       "876774520     14636\n",
       "131824507     11738\n",
       "2728353831    10225\n",
       "              ...  \n",
       "498100447         1\n",
       "150223908         1\n",
       "426436473         1\n",
       "1795622257        1\n",
       "2764201908        1\n",
       "Name: fea1_hash, Length: 4959, dtype: int64"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "features['fea1_hash'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>android_id</th>\n",
       "      <th>apptype</th>\n",
       "      <th>carrier</th>\n",
       "      <th>dev_height</th>\n",
       "      <th>dev_ppi</th>\n",
       "      <th>dev_width</th>\n",
       "      <th>media_id</th>\n",
       "      <th>ntt</th>\n",
       "      <th>osv</th>\n",
       "      <th>package</th>\n",
       "      <th>sid</th>\n",
       "      <th>timestamp</th>\n",
       "      <th>version</th>\n",
       "      <th>fea_hash</th>\n",
       "      <th>location</th>\n",
       "      <th>fea1_hash</th>\n",
       "      <th>cus_type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>317625</td>\n",
       "      <td>1181</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>2196.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1080.0</td>\n",
       "      <td>639</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8.10</td>\n",
       "      <td>188</td>\n",
       "      <td>1440682</td>\n",
       "      <td>2019-06-07 09:43:20.477148</td>\n",
       "      <td>7</td>\n",
       "      <td>1672223856</td>\n",
       "      <td>57</td>\n",
       "      <td>3872258917</td>\n",
       "      <td>658</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>435108</td>\n",
       "      <td>944</td>\n",
       "      <td>46003.0</td>\n",
       "      <td>2280.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1080.0</td>\n",
       "      <td>704</td>\n",
       "      <td>6.0</td>\n",
       "      <td>8.10</td>\n",
       "      <td>221</td>\n",
       "      <td>1606824</td>\n",
       "      <td>2019-06-05 20:53:33.449314</td>\n",
       "      <td>3</td>\n",
       "      <td>3767901757</td>\n",
       "      <td>23</td>\n",
       "      <td>129322164</td>\n",
       "      <td>943</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "      <td>1106</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>39</td>\n",
       "      <td>2.0</td>\n",
       "      <td>5.10</td>\n",
       "      <td>1562</td>\n",
       "      <td>1774642</td>\n",
       "      <td>2019-06-04 10:08:24.732394</td>\n",
       "      <td>0</td>\n",
       "      <td>454638703</td>\n",
       "      <td>30</td>\n",
       "      <td>4226678391</td>\n",
       "      <td>411</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>451504</td>\n",
       "      <td>761</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>1344.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>720.0</td>\n",
       "      <td>54</td>\n",
       "      <td>2.0</td>\n",
       "      <td>7.11</td>\n",
       "      <td>9</td>\n",
       "      <td>1742535</td>\n",
       "      <td>2019-06-05 01:03:10.643892</td>\n",
       "      <td>0</td>\n",
       "      <td>1507622951</td>\n",
       "      <td>65</td>\n",
       "      <td>3355419572</td>\n",
       "      <td>848</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>1001</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>665.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>320.0</td>\n",
       "      <td>29</td>\n",
       "      <td>5.0</td>\n",
       "      <td>8.10</td>\n",
       "      <td>4</td>\n",
       "      <td>1689686</td>\n",
       "      <td>2019-06-05 08:16:34.450110</td>\n",
       "      <td>0</td>\n",
       "      <td>4116351093</td>\n",
       "      <td>148</td>\n",
       "      <td>2644467751</td>\n",
       "      <td>411</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149995</th>\n",
       "      <td>0</td>\n",
       "      <td>1001</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>760.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>360.0</td>\n",
       "      <td>29</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8.10</td>\n",
       "      <td>4</td>\n",
       "      <td>1165373</td>\n",
       "      <td>2019-06-08 09:21:33.629823</td>\n",
       "      <td>0</td>\n",
       "      <td>3162887451</td>\n",
       "      <td>126</td>\n",
       "      <td>2711576615</td>\n",
       "      <td>411</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149996</th>\n",
       "      <td>0</td>\n",
       "      <td>1001</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>780.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>360.0</td>\n",
       "      <td>29</td>\n",
       "      <td>2.0</td>\n",
       "      <td>9.00</td>\n",
       "      <td>4</td>\n",
       "      <td>1444115</td>\n",
       "      <td>2019-06-07 07:15:57.431662</td>\n",
       "      <td>0</td>\n",
       "      <td>97238959</td>\n",
       "      <td>322</td>\n",
       "      <td>2678022183</td>\n",
       "      <td>411</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149997</th>\n",
       "      <td>0</td>\n",
       "      <td>1001</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>780.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>360.0</td>\n",
       "      <td>29</td>\n",
       "      <td>5.0</td>\n",
       "      <td>8.10</td>\n",
       "      <td>4</td>\n",
       "      <td>1134378</td>\n",
       "      <td>2019-06-09 08:48:59.661749</td>\n",
       "      <td>0</td>\n",
       "      <td>1320118495</td>\n",
       "      <td>46</td>\n",
       "      <td>2610913319</td>\n",
       "      <td>411</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149998</th>\n",
       "      <td>500925</td>\n",
       "      <td>1052</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>854.0</td>\n",
       "      <td>240.0</td>\n",
       "      <td>480.0</td>\n",
       "      <td>249</td>\n",
       "      <td>6.0</td>\n",
       "      <td>4.42</td>\n",
       "      <td>0</td>\n",
       "      <td>1700238</td>\n",
       "      <td>2019-06-05 06:38:14.527250</td>\n",
       "      <td>2</td>\n",
       "      <td>1292986591</td>\n",
       "      <td>41</td>\n",
       "      <td>1898209327</td>\n",
       "      <td>430</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149999</th>\n",
       "      <td>0</td>\n",
       "      <td>1001</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>780.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>360.0</td>\n",
       "      <td>29</td>\n",
       "      <td>2.0</td>\n",
       "      <td>9.00</td>\n",
       "      <td>4</td>\n",
       "      <td>1201539</td>\n",
       "      <td>2019-06-08 07:23:16.149025</td>\n",
       "      <td>0</td>\n",
       "      <td>259614175</td>\n",
       "      <td>122</td>\n",
       "      <td>2594136103</td>\n",
       "      <td>411</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>150000 rows × 17 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        android_id  apptype  carrier  dev_height  dev_ppi  dev_width  \\\n",
       "0           317625     1181  46000.0      2196.0      2.0     1080.0   \n",
       "1           435108      944  46003.0      2280.0      3.0     1080.0   \n",
       "2                0     1106  46000.0         0.0      0.0        0.0   \n",
       "3           451504      761  46000.0      1344.0      0.0      720.0   \n",
       "4                0     1001  46000.0       665.0      0.0      320.0   \n",
       "...            ...      ...      ...         ...      ...        ...   \n",
       "149995           0     1001  46000.0       760.0      0.0      360.0   \n",
       "149996           0     1001  46000.0       780.0      0.0      360.0   \n",
       "149997           0     1001  46000.0       780.0      0.0      360.0   \n",
       "149998      500925     1052  46000.0       854.0    240.0      480.0   \n",
       "149999           0     1001  46000.0       780.0      0.0      360.0   \n",
       "\n",
       "        media_id  ntt   osv  package      sid                  timestamp  \\\n",
       "0            639  2.0  8.10      188  1440682 2019-06-07 09:43:20.477148   \n",
       "1            704  6.0  8.10      221  1606824 2019-06-05 20:53:33.449314   \n",
       "2             39  2.0  5.10     1562  1774642 2019-06-04 10:08:24.732394   \n",
       "3             54  2.0  7.11        9  1742535 2019-06-05 01:03:10.643892   \n",
       "4             29  5.0  8.10        4  1689686 2019-06-05 08:16:34.450110   \n",
       "...          ...  ...   ...      ...      ...                        ...   \n",
       "149995        29  2.0  8.10        4  1165373 2019-06-08 09:21:33.629823   \n",
       "149996        29  2.0  9.00        4  1444115 2019-06-07 07:15:57.431662   \n",
       "149997        29  5.0  8.10        4  1134378 2019-06-09 08:48:59.661749   \n",
       "149998       249  6.0  4.42        0  1700238 2019-06-05 06:38:14.527250   \n",
       "149999        29  2.0  9.00        4  1201539 2019-06-08 07:23:16.149025   \n",
       "\n",
       "       version    fea_hash  location   fea1_hash  cus_type  \n",
       "0            7  1672223856        57  3872258917       658  \n",
       "1            3  3767901757        23   129322164       943  \n",
       "2            0   454638703        30  4226678391       411  \n",
       "3            0  1507622951        65  3355419572       848  \n",
       "4            0  4116351093       148  2644467751       411  \n",
       "...        ...         ...       ...         ...       ...  \n",
       "149995       0  3162887451       126  2711576615       411  \n",
       "149996       0    97238959       322  2678022183       411  \n",
       "149997       0  1320118495        46  2610913319       411  \n",
       "149998       2  1292986591        41  1898209327       430  \n",
       "149999       0   259614175       122  2594136103       411  \n",
       "\n",
       "[150000 rows x 17 columns]"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#对test数据集也采取同样的操作\r\n",
    "test_features=test[col]\r\n",
    "test_features"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/ipykernel_launcher.py:2: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>android_id</th>\n",
       "      <th>apptype</th>\n",
       "      <th>carrier</th>\n",
       "      <th>dev_height</th>\n",
       "      <th>dev_ppi</th>\n",
       "      <th>dev_width</th>\n",
       "      <th>media_id</th>\n",
       "      <th>ntt</th>\n",
       "      <th>osv</th>\n",
       "      <th>package</th>\n",
       "      <th>sid</th>\n",
       "      <th>timestamp</th>\n",
       "      <th>version</th>\n",
       "      <th>fea_hash</th>\n",
       "      <th>location</th>\n",
       "      <th>fea1_hash</th>\n",
       "      <th>cus_type</th>\n",
       "      <th>fea_hash_len</th>\n",
       "      <th>fea1_hash_len</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>317625</td>\n",
       "      <td>1181</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>2196.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1080.0</td>\n",
       "      <td>639</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8.10</td>\n",
       "      <td>188</td>\n",
       "      <td>1440682</td>\n",
       "      <td>2019-06-07 09:43:20.477148</td>\n",
       "      <td>7</td>\n",
       "      <td>1672223856</td>\n",
       "      <td>57</td>\n",
       "      <td>3872258917</td>\n",
       "      <td>658</td>\n",
       "      <td>10</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>435108</td>\n",
       "      <td>944</td>\n",
       "      <td>46003.0</td>\n",
       "      <td>2280.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1080.0</td>\n",
       "      <td>704</td>\n",
       "      <td>6.0</td>\n",
       "      <td>8.10</td>\n",
       "      <td>221</td>\n",
       "      <td>1606824</td>\n",
       "      <td>2019-06-05 20:53:33.449314</td>\n",
       "      <td>3</td>\n",
       "      <td>3767901757</td>\n",
       "      <td>23</td>\n",
       "      <td>129322164</td>\n",
       "      <td>943</td>\n",
       "      <td>10</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "      <td>1106</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>39</td>\n",
       "      <td>2.0</td>\n",
       "      <td>5.10</td>\n",
       "      <td>1562</td>\n",
       "      <td>1774642</td>\n",
       "      <td>2019-06-04 10:08:24.732394</td>\n",
       "      <td>0</td>\n",
       "      <td>454638703</td>\n",
       "      <td>30</td>\n",
       "      <td>4226678391</td>\n",
       "      <td>411</td>\n",
       "      <td>9</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>451504</td>\n",
       "      <td>761</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>1344.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>720.0</td>\n",
       "      <td>54</td>\n",
       "      <td>2.0</td>\n",
       "      <td>7.11</td>\n",
       "      <td>9</td>\n",
       "      <td>1742535</td>\n",
       "      <td>2019-06-05 01:03:10.643892</td>\n",
       "      <td>0</td>\n",
       "      <td>1507622951</td>\n",
       "      <td>65</td>\n",
       "      <td>3355419572</td>\n",
       "      <td>848</td>\n",
       "      <td>10</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>1001</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>665.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>320.0</td>\n",
       "      <td>29</td>\n",
       "      <td>5.0</td>\n",
       "      <td>8.10</td>\n",
       "      <td>4</td>\n",
       "      <td>1689686</td>\n",
       "      <td>2019-06-05 08:16:34.450110</td>\n",
       "      <td>0</td>\n",
       "      <td>4116351093</td>\n",
       "      <td>148</td>\n",
       "      <td>2644467751</td>\n",
       "      <td>411</td>\n",
       "      <td>10</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149995</th>\n",
       "      <td>0</td>\n",
       "      <td>1001</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>760.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>360.0</td>\n",
       "      <td>29</td>\n",
       "      <td>2.0</td>\n",
       "      <td>8.10</td>\n",
       "      <td>4</td>\n",
       "      <td>1165373</td>\n",
       "      <td>2019-06-08 09:21:33.629823</td>\n",
       "      <td>0</td>\n",
       "      <td>3162887451</td>\n",
       "      <td>126</td>\n",
       "      <td>2711576615</td>\n",
       "      <td>411</td>\n",
       "      <td>10</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149996</th>\n",
       "      <td>0</td>\n",
       "      <td>1001</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>780.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>360.0</td>\n",
       "      <td>29</td>\n",
       "      <td>2.0</td>\n",
       "      <td>9.00</td>\n",
       "      <td>4</td>\n",
       "      <td>1444115</td>\n",
       "      <td>2019-06-07 07:15:57.431662</td>\n",
       "      <td>0</td>\n",
       "      <td>97238959</td>\n",
       "      <td>322</td>\n",
       "      <td>2678022183</td>\n",
       "      <td>411</td>\n",
       "      <td>8</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149997</th>\n",
       "      <td>0</td>\n",
       "      <td>1001</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>780.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>360.0</td>\n",
       "      <td>29</td>\n",
       "      <td>5.0</td>\n",
       "      <td>8.10</td>\n",
       "      <td>4</td>\n",
       "      <td>1134378</td>\n",
       "      <td>2019-06-09 08:48:59.661749</td>\n",
       "      <td>0</td>\n",
       "      <td>1320118495</td>\n",
       "      <td>46</td>\n",
       "      <td>2610913319</td>\n",
       "      <td>411</td>\n",
       "      <td>10</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149998</th>\n",
       "      <td>500925</td>\n",
       "      <td>1052</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>854.0</td>\n",
       "      <td>240.0</td>\n",
       "      <td>480.0</td>\n",
       "      <td>249</td>\n",
       "      <td>6.0</td>\n",
       "      <td>4.42</td>\n",
       "      <td>0</td>\n",
       "      <td>1700238</td>\n",
       "      <td>2019-06-05 06:38:14.527250</td>\n",
       "      <td>2</td>\n",
       "      <td>1292986591</td>\n",
       "      <td>41</td>\n",
       "      <td>1898209327</td>\n",
       "      <td>430</td>\n",
       "      <td>10</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149999</th>\n",
       "      <td>0</td>\n",
       "      <td>1001</td>\n",
       "      <td>46000.0</td>\n",
       "      <td>780.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>360.0</td>\n",
       "      <td>29</td>\n",
       "      <td>2.0</td>\n",
       "      <td>9.00</td>\n",
       "      <td>4</td>\n",
       "      <td>1201539</td>\n",
       "      <td>2019-06-08 07:23:16.149025</td>\n",
       "      <td>0</td>\n",
       "      <td>259614175</td>\n",
       "      <td>122</td>\n",
       "      <td>2594136103</td>\n",
       "      <td>411</td>\n",
       "      <td>9</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>150000 rows × 19 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        android_id  apptype  carrier  dev_height  dev_ppi  dev_width  \\\n",
       "0           317625     1181  46000.0      2196.0      2.0     1080.0   \n",
       "1           435108      944  46003.0      2280.0      3.0     1080.0   \n",
       "2                0     1106  46000.0         0.0      0.0        0.0   \n",
       "3           451504      761  46000.0      1344.0      0.0      720.0   \n",
       "4                0     1001  46000.0       665.0      0.0      320.0   \n",
       "...            ...      ...      ...         ...      ...        ...   \n",
       "149995           0     1001  46000.0       760.0      0.0      360.0   \n",
       "149996           0     1001  46000.0       780.0      0.0      360.0   \n",
       "149997           0     1001  46000.0       780.0      0.0      360.0   \n",
       "149998      500925     1052  46000.0       854.0    240.0      480.0   \n",
       "149999           0     1001  46000.0       780.0      0.0      360.0   \n",
       "\n",
       "        media_id  ntt   osv  package      sid                  timestamp  \\\n",
       "0            639  2.0  8.10      188  1440682 2019-06-07 09:43:20.477148   \n",
       "1            704  6.0  8.10      221  1606824 2019-06-05 20:53:33.449314   \n",
       "2             39  2.0  5.10     1562  1774642 2019-06-04 10:08:24.732394   \n",
       "3             54  2.0  7.11        9  1742535 2019-06-05 01:03:10.643892   \n",
       "4             29  5.0  8.10        4  1689686 2019-06-05 08:16:34.450110   \n",
       "...          ...  ...   ...      ...      ...                        ...   \n",
       "149995        29  2.0  8.10        4  1165373 2019-06-08 09:21:33.629823   \n",
       "149996        29  2.0  9.00        4  1444115 2019-06-07 07:15:57.431662   \n",
       "149997        29  5.0  8.10        4  1134378 2019-06-09 08:48:59.661749   \n",
       "149998       249  6.0  4.42        0  1700238 2019-06-05 06:38:14.527250   \n",
       "149999        29  2.0  9.00        4  1201539 2019-06-08 07:23:16.149025   \n",
       "\n",
       "       version    fea_hash  location   fea1_hash  cus_type  fea_hash_len  \\\n",
       "0            7  1672223856        57  3872258917       658            10   \n",
       "1            3  3767901757        23   129322164       943            10   \n",
       "2            0   454638703        30  4226678391       411             9   \n",
       "3            0  1507622951        65  3355419572       848            10   \n",
       "4            0  4116351093       148  2644467751       411            10   \n",
       "...        ...         ...       ...         ...       ...           ...   \n",
       "149995       0  3162887451       126  2711576615       411            10   \n",
       "149996       0    97238959       322  2678022183       411             8   \n",
       "149997       0  1320118495        46  2610913319       411            10   \n",
       "149998       2  1292986591        41  1898209327       430            10   \n",
       "149999       0   259614175       122  2594136103       411             9   \n",
       "\n",
       "        fea1_hash_len  \n",
       "0                  10  \n",
       "1                   9  \n",
       "2                  10  \n",
       "3                  10  \n",
       "4                  10  \n",
       "...               ...  \n",
       "149995             10  \n",
       "149996             10  \n",
       "149997             10  \n",
       "149998             10  \n",
       "149999             10  \n",
       "\n",
       "[150000 rows x 19 columns]"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#然后对那几列的数据也采取相同的操作\r\n",
    "test_features['fea_hash_len']=test_features['fea_hash'].map(lambda x:len(str(x)) )\r\n",
    "test_features['fea1_hash_len']=test_features['fea1_hash'].map(lambda x:len(str(x)) )\r\n",
    "test_features['fea1_hash']=test_features['fea1_hash'].map(lambda x:0 if len(str(x))>16 else int(x))\r\n",
    "test_features['fea_hash']=test_features['fea_hash'].map(lambda x:0 if len(str(x))>16 else int(x))\r\n",
    "test_features"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 500000 entries, 0 to 499999\n",
      "Data columns (total 19 columns):\n",
      " #   Column         Non-Null Count   Dtype         \n",
      "---  ------         --------------   -----         \n",
      " 0   android_id     500000 non-null  int64         \n",
      " 1   apptype        500000 non-null  int64         \n",
      " 2   carrier        500000 non-null  float64       \n",
      " 3   dev_height     500000 non-null  float64       \n",
      " 4   dev_ppi        500000 non-null  float64       \n",
      " 5   dev_width      500000 non-null  float64       \n",
      " 6   media_id       500000 non-null  int64         \n",
      " 7   ntt            500000 non-null  float64       \n",
      " 8   osv            500000 non-null  float64       \n",
      " 9   package        500000 non-null  int64         \n",
      " 10  sid            500000 non-null  int64         \n",
      " 11  timestamp      500000 non-null  datetime64[ns]\n",
      " 12  version        500000 non-null  object        \n",
      " 13  fea_hash       500000 non-null  int64         \n",
      " 14  location       500000 non-null  int64         \n",
      " 15  fea1_hash      500000 non-null  int64         \n",
      " 16  cus_type       500000 non-null  int64         \n",
      " 17  fea_hash_len   500000 non-null  int64         \n",
      " 18  fea1_hash_len  500000 non-null  int64         \n",
      "dtypes: datetime64[ns](1), float64(6), int64(11), object(1)\n",
      "memory usage: 72.5+ MB\n"
     ]
    }
   ],
   "source": [
    "features.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 150000 entries, 0 to 149999\n",
      "Data columns (total 19 columns):\n",
      " #   Column         Non-Null Count   Dtype         \n",
      "---  ------         --------------   -----         \n",
      " 0   android_id     150000 non-null  int64         \n",
      " 1   apptype        150000 non-null  int64         \n",
      " 2   carrier        150000 non-null  float64       \n",
      " 3   dev_height     150000 non-null  float64       \n",
      " 4   dev_ppi        150000 non-null  float64       \n",
      " 5   dev_width      150000 non-null  float64       \n",
      " 6   media_id       150000 non-null  int64         \n",
      " 7   ntt            150000 non-null  float64       \n",
      " 8   osv            150000 non-null  float64       \n",
      " 9   package        150000 non-null  int64         \n",
      " 10  sid            150000 non-null  int64         \n",
      " 11  timestamp      150000 non-null  datetime64[ns]\n",
      " 12  version        150000 non-null  object        \n",
      " 13  fea_hash       150000 non-null  int64         \n",
      " 14  location       150000 non-null  int64         \n",
      " 15  fea1_hash      150000 non-null  int64         \n",
      " 16  cus_type       150000 non-null  int64         \n",
      " 17  fea_hash_len   150000 non-null  int64         \n",
      " 18  fea1_hash_len  150000 non-null  int64         \n",
      "dtypes: datetime64[ns](1), float64(6), int64(11), object(1)\n",
      "memory usage: 21.7+ MB\n"
     ]
    }
   ],
   "source": [
    "test_features.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>year</th>\n",
       "      <th>month</th>\n",
       "      <th>day</th>\n",
       "      <th>weekday</th>\n",
       "      <th>hour</th>\n",
       "      <th>minute</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "      <td>15</td>\n",
       "      <td>32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>8</td>\n",
       "      <td>5</td>\n",
       "      <td>19</td>\n",
       "      <td>40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>3</td>\n",
       "      <td>23</td>\n",
       "      <td>58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "      <td>8</td>\n",
       "      <td>59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "      <td>8</td>\n",
       "      <td>28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499995</th>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>3</td>\n",
       "      <td>23</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499996</th>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>3</td>\n",
       "      <td>17</td>\n",
       "      <td>40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499997</th>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499998</th>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499999</th>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "      <td>23</td>\n",
       "      <td>32</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>500000 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        year  month  day  weekday  hour  minute\n",
       "0       2019      6    7        4    15      32\n",
       "1       2019      6    8        5    19      40\n",
       "2       2019      6    6        3    23      58\n",
       "3       2019      6    9        6     8      59\n",
       "4       2019      6    7        4     8      28\n",
       "...      ...    ...  ...      ...   ...     ...\n",
       "499995  2019      6    6        3    23      14\n",
       "499996  2019      6    6        3    17      40\n",
       "499997  2019      6    5        2     3      14\n",
       "499998  2019      6    7        4     0      59\n",
       "499999  2019      6    7        4    23      32\n",
       "\n",
       "[500000 rows x 6 columns]"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#对训练集的 timestamp 提取时间多尺度\r\n",
    "temp=pd.DatetimeIndex(features['timestamp'])\r\n",
    "features['year']=temp.year\r\n",
    "features['month']=temp.month\r\n",
    "features['day']=temp.day\r\n",
    "features['weekday']=temp.weekday\r\n",
    "features['hour']=temp.hour\r\n",
    "features['minute']=temp.minute\r\n",
    "\r\n",
    "features[['year','month','day','weekday','hour','minute']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>timediff</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>4 days 15:32:07.066940</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>5 days 19:40:19.747448</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3 days 23:58:16.374328</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>6 days 08:59:36.544904</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4 days 08:28:20.303772</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499995</th>\n",
       "      <td>3 days 23:14:17.092461</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499996</th>\n",
       "      <td>3 days 17:40:52.870499</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499997</th>\n",
       "      <td>2 days 03:14:56.115283</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499998</th>\n",
       "      <td>4 days 00:59:26.476740</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499999</th>\n",
       "      <td>4 days 23:32:45.297448</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>500000 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                     timediff\n",
       "0      4 days 15:32:07.066940\n",
       "1      5 days 19:40:19.747448\n",
       "2      3 days 23:58:16.374328\n",
       "3      6 days 08:59:36.544904\n",
       "4      4 days 08:28:20.303772\n",
       "...                       ...\n",
       "499995 3 days 23:14:17.092461\n",
       "499996 3 days 17:40:52.870499\n",
       "499997 2 days 03:14:56.115283\n",
       "499998 4 days 00:59:26.476740\n",
       "499999 4 days 23:32:45.297448\n",
       "\n",
       "[500000 rows x 1 columns]"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#求时间的diff\r\n",
    "start_time=features['timestamp'].min()\r\n",
    "features['timediff']=features['timestamp']-start_time\r\n",
    "\r\n",
    "features[['timediff']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0         4.647303\n",
       "1         5.819664\n",
       "2         3.998796\n",
       "3         6.374722\n",
       "4         4.353009\n",
       "            ...   \n",
       "499995    3.968252\n",
       "499996    3.736713\n",
       "499997    2.135370\n",
       "499998    4.041273\n",
       "499999    4.981076\n",
       "Name: timediff, Length: 500000, dtype: float64"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "features['timediff']=features['timediff'].dt.days+features['timediff'].dt.seconds/3600/24\r\n",
    "features['timediff']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>timestamp</th>\n",
       "      <th>year</th>\n",
       "      <th>month</th>\n",
       "      <th>day</th>\n",
       "      <th>weekday</th>\n",
       "      <th>hour</th>\n",
       "      <th>minute</th>\n",
       "      <th>timediff</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-06-07 15:32:08.241721</td>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "      <td>15</td>\n",
       "      <td>32</td>\n",
       "      <td>4.647303</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-06-08 19:40:20.922229</td>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>8</td>\n",
       "      <td>5</td>\n",
       "      <td>19</td>\n",
       "      <td>40</td>\n",
       "      <td>5.819664</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2019-06-06 23:58:17.549109</td>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>3</td>\n",
       "      <td>23</td>\n",
       "      <td>58</td>\n",
       "      <td>3.998796</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2019-06-09 08:59:37.719685</td>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "      <td>8</td>\n",
       "      <td>59</td>\n",
       "      <td>6.374722</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2019-06-07 08:28:21.478553</td>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "      <td>8</td>\n",
       "      <td>28</td>\n",
       "      <td>4.353009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499995</th>\n",
       "      <td>2019-06-06 23:14:18.267242</td>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>3</td>\n",
       "      <td>23</td>\n",
       "      <td>14</td>\n",
       "      <td>3.968252</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499996</th>\n",
       "      <td>2019-06-06 17:40:54.045280</td>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>3</td>\n",
       "      <td>17</td>\n",
       "      <td>40</td>\n",
       "      <td>3.736713</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499997</th>\n",
       "      <td>2019-06-05 03:14:57.290064</td>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>14</td>\n",
       "      <td>2.135370</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499998</th>\n",
       "      <td>2019-06-07 00:59:27.651521</td>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>59</td>\n",
       "      <td>4.041273</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499999</th>\n",
       "      <td>2019-06-07 23:32:46.472229</td>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "      <td>23</td>\n",
       "      <td>32</td>\n",
       "      <td>4.981076</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>500000 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                        timestamp  year  month  day  weekday  hour  minute  \\\n",
       "0      2019-06-07 15:32:08.241721  2019      6    7        4    15      32   \n",
       "1      2019-06-08 19:40:20.922229  2019      6    8        5    19      40   \n",
       "2      2019-06-06 23:58:17.549109  2019      6    6        3    23      58   \n",
       "3      2019-06-09 08:59:37.719685  2019      6    9        6     8      59   \n",
       "4      2019-06-07 08:28:21.478553  2019      6    7        4     8      28   \n",
       "...                           ...   ...    ...  ...      ...   ...     ...   \n",
       "499995 2019-06-06 23:14:18.267242  2019      6    6        3    23      14   \n",
       "499996 2019-06-06 17:40:54.045280  2019      6    6        3    17      40   \n",
       "499997 2019-06-05 03:14:57.290064  2019      6    5        2     3      14   \n",
       "499998 2019-06-07 00:59:27.651521  2019      6    7        4     0      59   \n",
       "499999 2019-06-07 23:32:46.472229  2019      6    7        4    23      32   \n",
       "\n",
       "        timediff  \n",
       "0       4.647303  \n",
       "1       5.819664  \n",
       "2       3.998796  \n",
       "3       6.374722  \n",
       "4       4.353009  \n",
       "...          ...  \n",
       "499995  3.968252  \n",
       "499996  3.736713  \n",
       "499997  2.135370  \n",
       "499998  4.041273  \n",
       "499999  4.981076  \n",
       "\n",
       "[500000 rows x 8 columns]"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "features[['timestamp','year','month','day','weekday','hour','minute','timediff']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>year</th>\n",
       "      <th>month</th>\n",
       "      <th>day</th>\n",
       "      <th>weekday</th>\n",
       "      <th>hour</th>\n",
       "      <th>minute</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "      <td>9</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>20</td>\n",
       "      <td>53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>10</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>8</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149995</th>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>8</td>\n",
       "      <td>5</td>\n",
       "      <td>9</td>\n",
       "      <td>21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149996</th>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "      <td>7</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149997</th>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "      <td>8</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149998</th>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>6</td>\n",
       "      <td>38</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149999</th>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>8</td>\n",
       "      <td>5</td>\n",
       "      <td>7</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>150000 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        year  month  day  weekday  hour  minute\n",
       "0       2019      6    7        4     9      43\n",
       "1       2019      6    5        2    20      53\n",
       "2       2019      6    4        1    10       8\n",
       "3       2019      6    5        2     1       3\n",
       "4       2019      6    5        2     8      16\n",
       "...      ...    ...  ...      ...   ...     ...\n",
       "149995  2019      6    8        5     9      21\n",
       "149996  2019      6    7        4     7      15\n",
       "149997  2019      6    9        6     8      48\n",
       "149998  2019      6    5        2     6      38\n",
       "149999  2019      6    8        5     7      23\n",
       "\n",
       "[150000 rows x 6 columns]"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#对训练集的 timestamp 提取时间多尺度\r\n",
    "temp=pd.DatetimeIndex(test_features['timestamp'])\r\n",
    "test_features['year']=temp.year\r\n",
    "test_features['month']=temp.month\r\n",
    "test_features['day']=temp.day\r\n",
    "test_features['weekday']=temp.weekday\r\n",
    "test_features['hour']=temp.hour\r\n",
    "test_features['minute']=temp.minute\r\n",
    "\r\n",
    "test_features[['year','month','day','weekday','hour','minute']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>timestamp</th>\n",
       "      <th>year</th>\n",
       "      <th>month</th>\n",
       "      <th>day</th>\n",
       "      <th>weekday</th>\n",
       "      <th>hour</th>\n",
       "      <th>minute</th>\n",
       "      <th>timediff</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-06-07 09:43:20.477148</td>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "      <td>9</td>\n",
       "      <td>43</td>\n",
       "      <td>4.405081</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-06-05 20:53:33.449314</td>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>20</td>\n",
       "      <td>53</td>\n",
       "      <td>2.870509</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2019-06-04 10:08:24.732394</td>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>10</td>\n",
       "      <td>8</td>\n",
       "      <td>1.422488</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2019-06-05 01:03:10.643892</td>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>2.043854</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2019-06-05 08:16:34.450110</td>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>8</td>\n",
       "      <td>16</td>\n",
       "      <td>2.344826</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149995</th>\n",
       "      <td>2019-06-08 09:21:33.629823</td>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>8</td>\n",
       "      <td>5</td>\n",
       "      <td>9</td>\n",
       "      <td>21</td>\n",
       "      <td>5.389954</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149996</th>\n",
       "      <td>2019-06-07 07:15:57.431662</td>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "      <td>7</td>\n",
       "      <td>15</td>\n",
       "      <td>4.302731</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149997</th>\n",
       "      <td>2019-06-09 08:48:59.661749</td>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "      <td>8</td>\n",
       "      <td>48</td>\n",
       "      <td>6.367338</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149998</th>\n",
       "      <td>2019-06-05 06:38:14.527250</td>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>6</td>\n",
       "      <td>38</td>\n",
       "      <td>2.276539</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149999</th>\n",
       "      <td>2019-06-08 07:23:16.149025</td>\n",
       "      <td>2019</td>\n",
       "      <td>6</td>\n",
       "      <td>8</td>\n",
       "      <td>5</td>\n",
       "      <td>7</td>\n",
       "      <td>23</td>\n",
       "      <td>5.307801</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>150000 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                        timestamp  year  month  day  weekday  hour  minute  \\\n",
       "0      2019-06-07 09:43:20.477148  2019      6    7        4     9      43   \n",
       "1      2019-06-05 20:53:33.449314  2019      6    5        2    20      53   \n",
       "2      2019-06-04 10:08:24.732394  2019      6    4        1    10       8   \n",
       "3      2019-06-05 01:03:10.643892  2019      6    5        2     1       3   \n",
       "4      2019-06-05 08:16:34.450110  2019      6    5        2     8      16   \n",
       "...                           ...   ...    ...  ...      ...   ...     ...   \n",
       "149995 2019-06-08 09:21:33.629823  2019      6    8        5     9      21   \n",
       "149996 2019-06-07 07:15:57.431662  2019      6    7        4     7      15   \n",
       "149997 2019-06-09 08:48:59.661749  2019      6    9        6     8      48   \n",
       "149998 2019-06-05 06:38:14.527250  2019      6    5        2     6      38   \n",
       "149999 2019-06-08 07:23:16.149025  2019      6    8        5     7      23   \n",
       "\n",
       "        timediff  \n",
       "0       4.405081  \n",
       "1       2.870509  \n",
       "2       1.422488  \n",
       "3       2.043854  \n",
       "4       2.344826  \n",
       "...          ...  \n",
       "149995  5.389954  \n",
       "149996  4.302731  \n",
       "149997  6.367338  \n",
       "149998  2.276539  \n",
       "149999  5.307801  \n",
       "\n",
       "[150000 rows x 8 columns]"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_features['timediff']=test_features['timestamp']-start_time\r\n",
    "test_features['timediff']=test_features['timediff'].dt.days+test_features['timediff'].dt.seconds/3600/24\r\n",
    "\r\n",
    "test_features[['timestamp','year','month','day','weekday','hour','minute','timediff']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 500000 entries, 0 to 499999\n",
      "Data columns (total 26 columns):\n",
      " #   Column         Non-Null Count   Dtype         \n",
      "---  ------         --------------   -----         \n",
      " 0   android_id     500000 non-null  int64         \n",
      " 1   apptype        500000 non-null  int64         \n",
      " 2   carrier        500000 non-null  float64       \n",
      " 3   dev_height     500000 non-null  float64       \n",
      " 4   dev_ppi        500000 non-null  float64       \n",
      " 5   dev_width      500000 non-null  float64       \n",
      " 6   media_id       500000 non-null  int64         \n",
      " 7   ntt            500000 non-null  float64       \n",
      " 8   osv            500000 non-null  float64       \n",
      " 9   package        500000 non-null  int64         \n",
      " 10  sid            500000 non-null  int64         \n",
      " 11  timestamp      500000 non-null  datetime64[ns]\n",
      " 12  version        500000 non-null  object        \n",
      " 13  fea_hash       500000 non-null  int64         \n",
      " 14  location       500000 non-null  int64         \n",
      " 15  fea1_hash      500000 non-null  int64         \n",
      " 16  cus_type       500000 non-null  int64         \n",
      " 17  fea_hash_len   500000 non-null  int64         \n",
      " 18  fea1_hash_len  500000 non-null  int64         \n",
      " 19  year           500000 non-null  int64         \n",
      " 20  month          500000 non-null  int64         \n",
      " 21  day            500000 non-null  int64         \n",
      " 22  weekday        500000 non-null  int64         \n",
      " 23  hour           500000 non-null  int64         \n",
      " 24  minute         500000 non-null  int64         \n",
      " 25  timediff       500000 non-null  float64       \n",
      "dtypes: datetime64[ns](1), float64(7), int64(17), object(1)\n",
      "memory usage: 99.2+ MB\n"
     ]
    }
   ],
   "source": [
    "features.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 150000 entries, 0 to 149999\n",
      "Data columns (total 26 columns):\n",
      " #   Column         Non-Null Count   Dtype         \n",
      "---  ------         --------------   -----         \n",
      " 0   android_id     150000 non-null  int64         \n",
      " 1   apptype        150000 non-null  int64         \n",
      " 2   carrier        150000 non-null  float64       \n",
      " 3   dev_height     150000 non-null  float64       \n",
      " 4   dev_ppi        150000 non-null  float64       \n",
      " 5   dev_width      150000 non-null  float64       \n",
      " 6   media_id       150000 non-null  int64         \n",
      " 7   ntt            150000 non-null  float64       \n",
      " 8   osv            150000 non-null  float64       \n",
      " 9   package        150000 non-null  int64         \n",
      " 10  sid            150000 non-null  int64         \n",
      " 11  timestamp      150000 non-null  datetime64[ns]\n",
      " 12  version        150000 non-null  object        \n",
      " 13  fea_hash       150000 non-null  int64         \n",
      " 14  location       150000 non-null  int64         \n",
      " 15  fea1_hash      150000 non-null  int64         \n",
      " 16  cus_type       150000 non-null  int64         \n",
      " 17  fea_hash_len   150000 non-null  int64         \n",
      " 18  fea1_hash_len  150000 non-null  int64         \n",
      " 19  year           150000 non-null  int64         \n",
      " 20  month          150000 non-null  int64         \n",
      " 21  day            150000 non-null  int64         \n",
      " 22  weekday        150000 non-null  int64         \n",
      " 23  hour           150000 non-null  int64         \n",
      " 24  minute         150000 non-null  int64         \n",
      " 25  timediff       150000 non-null  float64       \n",
      "dtypes: datetime64[ns](1), float64(7), int64(17), object(1)\n",
      "memory usage: 29.8+ MB\n"
     ]
    }
   ],
   "source": [
    "test_features.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0            292156\n",
       "5             56691\n",
       "8             38348\n",
       "4             24262\n",
       "3             23857\n",
       "7             22801\n",
       "2             12750\n",
       "1              9184\n",
       "11             8867\n",
       "6              8527\n",
       "V3              806\n",
       "9               765\n",
       "v1              611\n",
       "10              126\n",
       "P_Final_6        92\n",
       "V6               88\n",
       "GA3              35\n",
       "GA2              10\n",
       "15                9\n",
       "V2                8\n",
       " 2                6\n",
       "50                1\n",
       "Name: version, dtype: int64"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#用一下version\r\n",
    "train['version'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "def version_trans(x):\r\n",
    "    if x==\"V3\":\r\n",
    "        return 3\r\n",
    "    if x==\"v1\":\r\n",
    "        return 1\r\n",
    "    if x==\"P_Final_6\":\r\n",
    "        return 6\r\n",
    "    if x==\"GA3\":\r\n",
    "        return 3   \r\n",
    "    if x==\"GA2\":\r\n",
    "        return 2   \r\n",
    "    if x==\"V2\":\r\n",
    "        return 2          \r\n",
    "    if x==\"V6\":\r\n",
    "        return 6                                     \r\n",
    "    return int(x)\r\n",
    "\r\n",
    "features['version']=features['version'].apply(version_trans).value_counts()\r\n",
    "test_features['version']=test_features['version'].apply(version_trans).value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 500000 entries, 0 to 499999\n",
      "Data columns (total 26 columns):\n",
      " #   Column         Non-Null Count   Dtype         \n",
      "---  ------         --------------   -----         \n",
      " 0   android_id     500000 non-null  int64         \n",
      " 1   apptype        500000 non-null  int64         \n",
      " 2   carrier        500000 non-null  float64       \n",
      " 3   dev_height     500000 non-null  float64       \n",
      " 4   dev_ppi        500000 non-null  float64       \n",
      " 5   dev_width      500000 non-null  float64       \n",
      " 6   media_id       500000 non-null  int64         \n",
      " 7   ntt            500000 non-null  float64       \n",
      " 8   osv            500000 non-null  float64       \n",
      " 9   package        500000 non-null  int64         \n",
      " 10  sid            500000 non-null  int64         \n",
      " 11  timestamp      500000 non-null  datetime64[ns]\n",
      " 12  version        14 non-null      float64       \n",
      " 13  fea_hash       500000 non-null  int64         \n",
      " 14  location       500000 non-null  int64         \n",
      " 15  fea1_hash      500000 non-null  int64         \n",
      " 16  cus_type       500000 non-null  int64         \n",
      " 17  fea_hash_len   500000 non-null  int64         \n",
      " 18  fea1_hash_len  500000 non-null  int64         \n",
      " 19  year           500000 non-null  int64         \n",
      " 20  month          500000 non-null  int64         \n",
      " 21  day            500000 non-null  int64         \n",
      " 22  weekday        500000 non-null  int64         \n",
      " 23  hour           500000 non-null  int64         \n",
      " 24  minute         500000 non-null  int64         \n",
      " 25  timediff       500000 non-null  float64       \n",
      "dtypes: datetime64[ns](1), float64(8), int64(17)\n",
      "memory usage: 99.2 MB\n"
     ]
    }
   ],
   "source": [
    "features.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 150000 entries, 0 to 149999\n",
      "Data columns (total 26 columns):\n",
      " #   Column         Non-Null Count   Dtype         \n",
      "---  ------         --------------   -----         \n",
      " 0   android_id     150000 non-null  int64         \n",
      " 1   apptype        150000 non-null  int64         \n",
      " 2   carrier        150000 non-null  float64       \n",
      " 3   dev_height     150000 non-null  float64       \n",
      " 4   dev_ppi        150000 non-null  float64       \n",
      " 5   dev_width      150000 non-null  float64       \n",
      " 6   media_id       150000 non-null  int64         \n",
      " 7   ntt            150000 non-null  float64       \n",
      " 8   osv            150000 non-null  float64       \n",
      " 9   package        150000 non-null  int64         \n",
      " 10  sid            150000 non-null  int64         \n",
      " 11  timestamp      150000 non-null  datetime64[ns]\n",
      " 12  version        15 non-null      float64       \n",
      " 13  fea_hash       150000 non-null  int64         \n",
      " 14  location       150000 non-null  int64         \n",
      " 15  fea1_hash      150000 non-null  int64         \n",
      " 16  cus_type       150000 non-null  int64         \n",
      " 17  fea_hash_len   150000 non-null  int64         \n",
      " 18  fea1_hash_len  150000 non-null  int64         \n",
      " 19  year           150000 non-null  int64         \n",
      " 20  month          150000 non-null  int64         \n",
      " 21  day            150000 non-null  int64         \n",
      " 22  weekday        150000 non-null  int64         \n",
      " 23  hour           150000 non-null  int64         \n",
      " 24  minute         150000 non-null  int64         \n",
      " 25  timediff       150000 non-null  float64       \n",
      "dtypes: datetime64[ns](1), float64(8), int64(17)\n",
      "memory usage: 29.8 MB\n"
     ]
    }
   ],
   "source": [
    "test_features.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "features['version']=features['version'].astype(float)\r\n",
    "test_features['version']=test_features['version'].astype(float)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "训练集的特征: Index(['android_id', 'apptype', 'carrier', 'dev_height', 'dev_ppi',\n",
      "       'dev_width', 'media_id', 'ntt', 'osv', 'package', 'sid', 'timestamp',\n",
      "       'version', 'fea_hash', 'location', 'fea1_hash', 'cus_type',\n",
      "       'fea_hash_len', 'fea1_hash_len', 'year', 'month', 'day', 'weekday',\n",
      "       'hour', 'minute', 'timediff'],\n",
      "      dtype='object')\n",
      "测试集的特征: Index(['android_id', 'apptype', 'carrier', 'dev_height', 'dev_ppi',\n",
      "       'dev_width', 'media_id', 'ntt', 'osv', 'package', 'sid', 'timestamp',\n",
      "       'version', 'fea_hash', 'location', 'fea1_hash', 'cus_type',\n",
      "       'fea_hash_len', 'fea1_hash_len', 'year', 'month', 'day', 'weekday',\n",
      "       'hour', 'minute', 'timediff'],\n",
      "      dtype='object')\n"
     ]
    }
   ],
   "source": [
    "print(\"训练集的特征:\",features.columns)\r\n",
    "print(\"测试集的特征:\",test_features.columns)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style type='text/css'>\n",
       ".datatable table.frame { margin-bottom: 0; }\n",
       ".datatable table.frame thead { border-bottom: none; }\n",
       ".datatable table.frame tr.coltypes td {  color: #FFFFFF;  line-height: 6px;  padding: 0 0.5em;}\n",
       ".datatable .bool    { background: #DDDD99; }\n",
       ".datatable .object  { background: #565656; }\n",
       ".datatable .int     { background: #5D9E5D; }\n",
       ".datatable .float   { background: #4040CC; }\n",
       ".datatable .str     { background: #CC4040; }\n",
       ".datatable .row_index {  background: var(--jp-border-color3);  border-right: 1px solid var(--jp-border-color0);  color: var(--jp-ui-font-color3);  font-size: 9px;}\n",
       ".datatable .frame tr.coltypes .row_index {  background: var(--jp-border-color0);}\n",
       ".datatable th:nth-child(2) { padding-left: 12px; }\n",
       ".datatable .hellipsis {  color: var(--jp-cell-editor-border-color);}\n",
       ".datatable .vellipsis {  background: var(--jp-layout-color0);  color: var(--jp-cell-editor-border-color);}\n",
       ".datatable .na {  color: var(--jp-cell-editor-border-color);  font-size: 80%;}\n",
       ".datatable .footer { font-size: 9px; }\n",
       ".datatable .frame_dimensions {  background: var(--jp-border-color3);  border-top: 1px solid var(--jp-border-color0);  color: var(--jp-ui-font-color3);  display: inline-block;  opacity: 0.6;  padding: 1px 10px 1px 5px;}\n",
       "</style>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "LGBMClassifier(boosting_type='gbdt', class_weight=None, colsample_bytree=1.0,\n",
       "               importance_type='split', learning_rate=0.1, max_depth=-1,\n",
       "               min_child_samples=20, min_child_weight=0.001, min_split_gain=0.0,\n",
       "               n_estimators=100, n_jobs=-1, num_leaves=31, objective=None,\n",
       "               random_state=None, reg_alpha=0.0, reg_lambda=0.0, silent=True,\n",
       "               subsample=1.0, subsample_for_bin=200000, subsample_freq=0)"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#有了特征和标签 这个时候就可以来建模来训练了 并得出结果了\r\n",
    "import lightgbm as lgb\r\n",
    "model=lgb.LGBMClassifier()\r\n",
    "#模型训练\r\n",
    "model.fit(features.drop(['timestamp'],axis=1),train['label'] )#把去掉timestamp后的特征 训练    标签是train的label\r\n",
    "model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 0, 0, ..., 1, 1, 1])"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result=model.predict(test_features.drop(['timestamp'],axis=1))\r\n",
    "result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['android_id', 'apptype', 'carrier', 'dev_height', 'dev_ppi',\n",
       "       'dev_width', 'lan', 'media_id', 'ntt', 'os', 'osv', 'package', 'sid',\n",
       "       'timestamp', 'version', 'fea_hash', 'location', 'fea1_hash',\n",
       "       'cus_type'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>sid</th>\n",
       "      <th>label</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1440682</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1606824</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1774642</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1742535</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1689686</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149995</th>\n",
       "      <td>1165373</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149996</th>\n",
       "      <td>1444115</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149997</th>\n",
       "      <td>1134378</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149998</th>\n",
       "      <td>1700238</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149999</th>\n",
       "      <td>1201539</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>150000 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            sid  label\n",
       "0       1440682      0\n",
       "1       1606824      0\n",
       "2       1774642      0\n",
       "3       1742535      0\n",
       "4       1689686      1\n",
       "...         ...    ...\n",
       "149995  1165373      1\n",
       "149996  1444115      1\n",
       "149997  1134378      1\n",
       "149998  1700238      1\n",
       "149999  1201539      1\n",
       "\n",
       "[150000 rows x 2 columns]"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#把结果编程一个result\r\n",
    "res=pd.DataFrame(test['sid'])\r\n",
    "res['label']=result\r\n",
    "res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "res.to_csv('./321.csv',index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0         1440682\n",
       "1         1606824\n",
       "2         1774642\n",
       "3         1742535\n",
       "4         1689686\n",
       "           ...   \n",
       "149995    1165373\n",
       "149996    1444115\n",
       "149997    1134378\n",
       "149998    1700238\n",
       "149999    1201539\n",
       "Name: sid, Length: 150000, dtype: int64"
      ]
     },
     "execution_count": null,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test['sid']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "PaddlePaddle 2.1.0 (Python 3.5)",
   "language": "python",
   "name": "py35-paddle1.2.0"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
